(* Content-type: application/vnd.wolfram.mathematica *)

(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)

(* CreatedBy='Mathematica 13.2' *)

(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[       158,          7]
NotebookDataLength[    107865,       2455]
NotebookOptionsPosition[    102845,       2384]
NotebookOutlinePosition[    103242,       2400]
CellTagsIndexPosition[    103199,       2397]
WindowFrame->Normal*)

(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{
   RowBox[{"--", 
    RowBox[{"--", 
     RowBox[{"-", "Full"}]}]}], ",", " ", 
   RowBox[{
    RowBox[{"Imperfect", " ", "Altruism", " ", 
     RowBox[{"(", 
      RowBox[{"\[Omega]", "=", "0"}], ")"}]}], " ", "+", " ", 
    RowBox[{"Decomposition", " ", "Into", " ", "Individual", " ", 
     RowBox[{
      RowBox[{"Effects", "--"}], "--"}]}], "-"}]}], "*)"}]], "Input",
 CellChangeTimes->{{3.9027274914266653`*^9, 3.902727498357554*^9}},
 CellLabel->"In[1]:=",ExpressionUUID->"72dbc847-9a88-4552-afb1-dde02e0e8916"],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{"Fixed", " ", 
   RowBox[{
    RowBox[{
     SubscriptBox["D", "t"], " ", "--"}], "--"}], " ", "Full", " ", "Model"}],
   "*)"}]], "Input",
 CellChangeTimes->{{3.899790189998526*^9, 3.899790192054748*^9}, {
  3.902727500689454*^9, 3.902727501190166*^9}},
 CellLabel->"In[2]:=",ExpressionUUID->"718de337-52d2-4236-91a8-b29b21012d14"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"gDCutoffConsProd", "=", "gDCutoffsparm"}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"gDCutoffConsProd", "[", 
    RowBox[{"[", 
     RowBox[{"All", ",", "2"}], "]"}], "]"}], "=", "1"}], ";"}]}], "Input",
 CellChangeTimes->{{3.902987716662806*^9, 3.902987742244266*^9}},
 CellLabel->"In[11]:=",ExpressionUUID->"bb492a35-4d3f-41ac-9cef-2f281b17d81e"],

Cell[BoxData[
 RowBox[{
  RowBox[{"inputDataConsProd", "=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
     RowBox[{
     "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], ",", 
     RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
     RowBox[{"gNCutoffs", "\[Rule]", "gNCutoffsparms"}], ",", 
     RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
     RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
     RowBox[{"gDCutoffs", "\[Rule]", "gDCutoffConsProd"}], ",", 
     RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
     RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
     RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
     RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
     RowBox[{"Pie", "\[Rule]", 
      RowBox[{"smoothedpie", "[", 
       RowBox[{"[", 
        RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
     RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
     RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
     RowBox[{"precision", "\[Rule]", "precisionparm"}], ",", 
     RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
     RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
     RowBox[{"time", "\[Rule]", "timeparm"}], ",", 
     RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
     RowBox[{"Pie28", "\[Rule]", 
      RowBox[{"smoothedpie", "[", 
       RowBox[{"[", 
        RowBox[{"30", ",", "2"}], "]"}], "]"}]}], ",", 
     RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
     RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";"}]], "Input",
 CellChangeTimes->{
  3.90298769478279*^9, {3.902987752923338*^9, 3.9029877726379013`*^9}},
 CellLabel->"In[13]:=",ExpressionUUID->"6c2681cd-2ec2-4472-8fcd-dfe31a54ff13"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"{", 
    RowBox[{
    "initialDistributionConsProd", ",", "allParmsConsProd", ",", 
     "averageBeta2000ConsProd"}], "}"}], "=", 
   RowBox[{"findInitialDistributionHelper", "[", "inputDataConsProd", "]"}]}],
   ";"}]], "Input",
 CellChangeTimes->{{3.8997906784686527`*^9, 3.899790692883472*^9}},
 CellLabel->"In[14]:=",ExpressionUUID->"78632e09-26a0-489a-8087-54a525f6305a"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ansConsProd", "=", 
   RowBox[{"solveModelHelper", "[", 
    RowBox[{
    "inputDataConsProd", ",", "initpointsFull", ",", 
     "initialDistributionConsProd", ",", "allParmsConsProd"}], "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.89695018329387*^9, 3.896950192557602*^9}, 
   3.898833822925235*^9, 3.8988360818422213`*^9, {3.899790220826426*^9, 
   3.899790261774736*^9}, {3.8997903707080717`*^9, 3.899790371064666*^9}, {
   3.8997907033674603`*^9, 3.899790706081188*^9}},
 CellLabel->"In[15]:=",ExpressionUUID->"43296670-d310-42a5-8ec5-563e504e15b2"],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{"--", 
   RowBox[{"--", 
    RowBox[{"--", 
     RowBox[{"--", 
      RowBox[{"--", "--"}]}]}]}]}], "*)"}]], "Input",
 CellChangeTimes->{{3.896934784371644*^9, 3.896934785665431*^9}, {
  3.90272864741265*^9, 3.9027286497633877`*^9}},
 CellLabel->"In[9]:=",ExpressionUUID->"c1f3a51c-b7d6-4ac6-bb24-35f14cf3a0cf"],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{"Fixed", " ", 
   RowBox[{
    RowBox[{"Pie", " ", "--"}], "--"}], " ", "Full", " ", "Model"}], 
  "*)"}]], "Input",
 CellChangeTimes->{
  3.896935458411422*^9, {3.902728644330751*^9, 3.902728658009582*^9}},
 CellLabel->"In[10]:=",ExpressionUUID->"e39e5057-f3d6-42da-a5ce-5a1fba26e33e"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"initialList", "=", 
   RowBox[{"Pie", "/.", "inputDataFull"}]}], ";"}], "\n", 
 RowBox[{
  RowBox[{"targetList", "=", 
   RowBox[{"ConstantArray", "[", 
    RowBox[{
     RowBox[{"Piess", "/.", "inputDataFull"}], ",", 
     RowBox[{"Length", "[", "initialList", "]"}]}], "]"}]}], ";"}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"numberOfSteps", "=", "5"}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{"Adjust", " ", "this", " ", "value", " ", "as", " ", "needed"}], 
   "*)"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"interpolationList", "=", 
   RowBox[{"InterpolateLists", "[", 
    RowBox[{
    "initialList", ",", "targetList", ",", "numberOfSteps", ",", 
     "\"\<b-spline\>\""}], "]"}]}], ";"}]}], "Input",
 CellChangeTimes->{{3.89693579332733*^9, 3.896935817809792*^9}, {
  3.896945571286508*^9, 3.8969455822287617`*^9}, {3.89695068777496*^9, 
  3.896950716831942*^9}, {3.8969516500198727`*^9, 3.896951651812216*^9}, {
  3.896951708273746*^9, 3.896951710000708*^9}, {3.899791048617293*^9, 
  3.8997910585340567`*^9}},
 CellLabel->"In[16]:=",ExpressionUUID->"0471509b-c23a-4774-b1f7-9d01592ab201"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"initpoints", "=", 
   RowBox[{"Join", "[", 
    RowBox[{
     RowBox[{"ansFull", "[", 
      RowBox[{"[", "2", "]"}], "]"}], ",", 
     RowBox[{"ansFull", "[", 
      RowBox[{"[", "4", "]"}], "]"}]}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"For", "[", 
   RowBox[{
    RowBox[{"k", "=", "2"}], ",", 
    RowBox[{"k", "<=", 
     RowBox[{"numberOfSteps", "+", "1"}]}], ",", 
    RowBox[{"k", "++"}], ",", "\[IndentingNewLine]", 
    RowBox[{
     RowBox[{"PrintTemporary", "[", "k", "]"}], ";", "\[IndentingNewLine]", 
     RowBox[{"smoothedpieCons", "=", 
      RowBox[{"interpolationList", "[", 
       RowBox[{"[", "k", "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
     "\[IndentingNewLine]", 
     RowBox[{"inputDataConsProb", "=", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
        RowBox[{
        "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], 
        ",", 
        RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
        RowBox[{"gNCutoffs", "\[Rule]", "gNCutoffsparms"}], ",", 
        RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
        RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
        RowBox[{"gDCutoffs", "\[Rule]", "gDCutoffsparm"}], ",", 
        RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
        RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
        RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
        RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
        RowBox[{"Pie", "\[Rule]", "smoothedpieCons"}], ",", 
        RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
        RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
        RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
        RowBox[{"precision", "\[Rule]", "precisionparm"}], ",", 
        RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
        RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
        RowBox[{"time", "\[Rule]", "timeparm"}], ",", 
        RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
        RowBox[{"Pie28", "\[Rule]", 
         RowBox[{"smoothedpieCons", "[", 
          RowBox[{"[", "30", "]"}], "]"}]}], ",", 
        RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
        RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";", 
     "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
     RowBox[{"(*", 
      RowBox[{
       RowBox[{"inputDataConsProb", "=", 
        RowBox[{"{", 
         RowBox[{
          RowBox[{"lrintr", "\[Rule]", "0.064"}], ",", 
          RowBox[{"matchlrirBaselinyears", "\[Rule]", "100"}], ",", 
          RowBox[{"stdevbeta", "\[Rule]", "0.0053"}], ",", 
          RowBox[{"gNCutoffs", "\[Rule]", 
           RowBox[{"{", 
            RowBox[{
             RowBox[{"{", 
              RowBox[{"1700", ",", "1.030615194"}], "}"}], ",", 
             RowBox[{"{", 
              RowBox[{"1875", ",", "1.118744119"}], "}"}], ",", 
             RowBox[{"{", 
              RowBox[{"2000", ",", "1.356358323"}], "}"}]}], "}"}]}], ",", 
          RowBox[{"gNyearsFuture", "\[Rule]", "100"}], ",", 
          RowBox[{"gNss", "\[Rule]", 
           SuperscriptBox["0.99", "25"]}], ",", 
          RowBox[{"gDCutoffs", "\[Rule]", 
           RowBox[{"{", 
            RowBox[{
             RowBox[{"{", 
              RowBox[{"1775", ",", "0.9870600798536096`"}], "}"}], ",", 
             RowBox[{"{", 
              RowBox[{"1875", ",", "1.0691884259095668`"}], "}"}], ",", 
             RowBox[{"{", 
              RowBox[{"2000", ",", "1.2796887955836727`"}], "}"}]}], "}"}]}], 
          ",", 
          RowBox[{"gDyearsFuture", "\[Rule]", "100"}], ",", 
          RowBox[{"gDss", "\[Rule]", 
           SuperscriptBox["1.005", "25"]}], ",", 
          RowBox[{"\[Nu]", "\[Rule]", "0.33"}], ",", 
          RowBox[{"\[Delta]", "\[Rule]", 
           RowBox[{"1", "-", 
            SuperscriptBox[
             RowBox[{"(", 
              RowBox[{"1", "-", "0.1"}], ")"}], "25"]}]}], ",", 
          RowBox[{"Pie", "\[Rule]", "smoothedpieCons"}], ",", 
          RowBox[{"Piess", "\[Rule]", "0.666667"}], ",", 
          RowBox[{"lrconssh", "\[Rule]", "0.75"}], ",", 
          RowBox[{"nTypes", "\[Rule]", "10000"}], ",", 
          RowBox[{"precision", "\[Rule]", "100"}], ",", 
          RowBox[{"inityear", "\[Rule]", "1300"}], ",", 
          RowBox[{"currentyear", "\[Rule]", "2000"}], ",", " ", 
          RowBox[{"time", "\[Rule]", "200"}], ",", 
          RowBox[{"\[Omega]", "\[Rule]", "0"}], ",", 
          RowBox[{"Pie28", "\[Rule]", 
           RowBox[{"smoothedpieCons", "[", 
            RowBox[{"[", "30", "]"}], "]"}]}]}], "}"}]}], ";"}], "*)"}], 
     "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
     "\[IndentingNewLine]", 
     RowBox[{
      RowBox[{"{", 
       RowBox[{
       "initialDistributionConsProb", ",", "allParmsConsProb", ",", 
        "averageBeta2000ConsProb"}], "}"}], "=", 
      RowBox[{"findInitialDistributionHelper", "[", "inputDataFull", "]"}]}], 
     ";", " ", 
     RowBox[{"(*", 
      RowBox[{
       RowBox[{
       "We", " ", "can", " ", "use", " ", "inputDataFull", " ", "here", " ", 
        "instead", " ", "of", " ", "inputDataConsProb", " ", "because", " ", 
        "the", " ", "findInitialDistributionHelper", " ", "module", " ", "is",
         " ", "meomized", " ", "and", " ", "whilst", " ", "inputDataConsProb",
         " ", "changes", " ", "with", " ", "each", " ", "iteration"}], ",", 
       " ", 
       RowBox[{"inputDataFull", " ", 
        RowBox[{"doesn", "'"}], 
        RowBox[{"t", ".", " ", "The"}], " ", "relevant", " ", "parameters", 
        " ", "in", " ", "inputDataFull", " ", "are", " ", "the", " ", "same", 
        " ", "as", " ", "in", " ", "inputDataConsProb"}]}], "*)"}], 
     "\[IndentingNewLine]", 
     RowBox[{"ansConsProb", "=", 
      RowBox[{"solveModelHelper", "[", 
       RowBox[{
       "inputDataConsProb", ",", "initpoints", ",", 
        "initialDistributionConsProb", ",", "allParmsConsProb"}], "]"}]}], 
     ";", "\[IndentingNewLine]", 
     RowBox[{"initpoints", "=", 
      RowBox[{"Join", "[", 
       RowBox[{
        RowBox[{"ansConsProb", "[", 
         RowBox[{"[", "2", "]"}], "]"}], ",", 
        RowBox[{"ansConsProb", "[", 
         RowBox[{"[", "4", "]"}], "]"}]}], "]"}]}], ";"}]}], 
   "\[IndentingNewLine]", "\[IndentingNewLine]", "]"}], ";"}]}], "Input",
 CellChangeTimes->{{3.894602203586357*^9, 3.89460224067334*^9}, {
   3.894602313641918*^9, 3.894602325878001*^9}, {3.8946026628232603`*^9, 
   3.894602664973299*^9}, 3.8946026996607122`*^9, 3.894604346911193*^9, 
   3.894942151977762*^9, {3.894943698880231*^9, 3.894943705866322*^9}, {
   3.8949437540126343`*^9, 3.894943757607161*^9}, {3.894945734750021*^9, 
   3.8949457450623913`*^9}, 3.895033242378134*^9, 3.8969359417931767`*^9, {
   3.8969369473720903`*^9, 3.896936974798514*^9}, {3.89693878985373*^9, 
   3.8969387992550364`*^9}, {3.896951368935038*^9, 3.896951383236205*^9}, {
   3.8969515264692783`*^9, 3.896951527628043*^9}, {3.8969515595756083`*^9, 
   3.896951646472106*^9}, {3.8969518629336042`*^9, 3.8969519130273647`*^9}, {
   3.896952005776239*^9, 3.896952007704317*^9}, {3.896953390710103*^9, 
   3.8969534034923964`*^9}, {3.897020137104067*^9, 3.897020145230077*^9}, {
   3.8970225444371367`*^9, 3.897022571455357*^9}, {3.898765860830114*^9, 
   3.8987658728023853`*^9}, {3.898765956599702*^9, 3.898765986501594*^9}, 
   3.898836065678749*^9, {3.89883613261698*^9, 3.8988361850420227`*^9}, {
   3.898836282795487*^9, 3.898836309460195*^9}, {3.8997910695720377`*^9, 
   3.899791092885108*^9}, 3.8997911348496037`*^9, {3.899791166638424*^9, 
   3.8997912109756813`*^9}, {3.9027283465149603`*^9, 3.902728347541243*^9}, {
   3.902987874424279*^9, 3.902987905297957*^9}, {3.9029884198255157`*^9, 
   3.902988490557481*^9}, 3.902991998364036*^9, {3.902992421608202*^9, 
   3.9029924217647142`*^9}},
 CellLabel->"In[20]:=",ExpressionUUID->"5c4ba096-8199-4b91-b92e-45c00fe62a84"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"smoothedpieCons", "=", 
   RowBox[{"interpolationList", "[", 
    RowBox[{"[", "6", "]"}], "]"}]}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"inputDataConsProb", "=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
     RowBox[{
     "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], ",", 
     RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
     RowBox[{"gNCutoffs", "\[Rule]", "gNCutoffsparms"}], ",", 
     RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
     RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
     RowBox[{"gDCutoffs", "\[Rule]", "gDCutoffsparm"}], ",", 
     RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
     RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
     RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
     RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
     RowBox[{"Pie", "\[Rule]", "smoothedpieCons"}], ",", 
     RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
     RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
     RowBox[{"precision", "\[Rule]", "precisionparm"}], ",", 
     RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
     RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
     RowBox[{"time", "\[Rule]", "timeparm"}], ",", 
     RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
     RowBox[{"Pie28", "\[Rule]", 
      RowBox[{"smoothedpieCons", "[", 
       RowBox[{"[", "30", "]"}], "]"}]}], ",", 
     RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
     RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";"}]}], "Input",
 CellChangeTimes->{{3.898838657119979*^9, 3.898838657218721*^9}, {
   3.898839742658621*^9, 3.898839742889916*^9}, 3.899791948933011*^9, {
   3.902988557641284*^9, 3.902988568502339*^9}, 3.9029924550444508`*^9},
 CellLabel->"In[22]:=",ExpressionUUID->"6090a775-fc0d-4b12-a4ed-21df908219e5"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"{", 
    RowBox[{
    "initialDistributionConsProb", ",", "allParmsConsProb", ",", 
     "averageBeta2000ConsProb"}], "}"}], "=", 
   RowBox[{"findInitialDistributionHelper", "[", "inputDataConsProb", "]"}]}],
   ";"}]], "Input",
 CellChangeTimes->{
  3.8988363865198393`*^9, 3.898836974238018*^9, {3.898837015046914*^9, 
   3.898837023015511*^9}, {3.898837101748519*^9, 3.898837106556628*^9}, {
   3.898838664729759*^9, 3.8988386666695147`*^9}, {3.89883878083106*^9, 
   3.898838782237557*^9}, {3.898839741713592*^9, 3.898839746294881*^9}, {
   3.8997919537726507`*^9, 3.899791964775807*^9}},
 CellLabel->"In[24]:=",ExpressionUUID->"6d09ece2-981a-4c29-8f03-f34bf5f9ef60"],

Cell[BoxData[
 RowBox[{
  RowBox[{"initpointsx", "=", 
   RowBox[{"Join", "[", 
    RowBox[{
     RowBox[{"ansConsProb", "[", 
      RowBox[{"[", "2", "]"}], "]"}], ",", 
     RowBox[{"ansConsProb", "[", 
      RowBox[{"[", "4", "]"}], "]"}]}], "]"}]}], ";"}]], "Input",
 CellChangeTimes->{
  3.89695370058444*^9, {3.8997928499093113`*^9, 3.899792850213694*^9}},
 CellLabel->"In[25]:=",ExpressionUUID->"1d41a10a-8d52-4450-bee2-cf769fc0ee43"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{
  "testansConsProb", " ", "function", " ", "to", " ", "recalibrate", " ", 
   "new", " ", "productivity", " ", "growth", " ", "rates"}], "*)"}]], "Input",\

 CellGroupingRules->{"GroupTogetherGrouping", 10001.},
 CellChangeTimes->{{3.896937561517844*^9, 3.89693761672165*^9}, 
   3.897024176509036*^9},
 CellLabel->"In[27]:=",ExpressionUUID->"956b7155-555f-4347-9093-c4ce79e18db0"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"counter", "=", "0"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"testansConsProb", "[", 
     RowBox[{"aa_", ",", "bb_", ",", "cc_"}], "]"}], ":=", 
    RowBox[{
     RowBox[{"testansConsProb", "[", 
      RowBox[{"aa", ",", "bb", ",", "cc"}], "]"}], "=", "\[IndentingNewLine]", 
     RowBox[{"Module", "[", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
        "inputData", ",", "allParmsOriginal", ",", "distt2000", ",", 
         "averageBeta2000", ",", "initialDistributionTilde", ",", "pp", ",", 
         "temp", ",", "points", ",", " ", "points2", ",", "ans5", ",", 
         "grrates", ",", "averageBeta2000ans5", ",", "allParmsans5", ",", 
         "ipoints", ",", "allParms"}], "}"}], ",", "\[IndentingNewLine]", 
       "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{
         RowBox[{"inputData", "=", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"lrintr", "\[Rule]", "0.064"}], ",", 
            RowBox[{"matchlrirBaselinyears", "\[Rule]", "100"}], ",", 
            RowBox[{"stdevbeta", "\[Rule]", "0.0053"}], ",", 
            RowBox[{"gNCutoffs", "\[Rule]", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{"{", 
                RowBox[{"1775", ",", "1.0223498"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"1875", ",", "1.106957"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"2000", ",", "1.281668"}], "}"}]}], "}"}]}], ",", 
            RowBox[{"gNyearsFuture", "\[Rule]", "100"}], ",", 
            RowBox[{"gNss", "\[Rule]", 
             SuperscriptBox["0.99", "25"]}], ",", 
            RowBox[{"gDCutoffs", "\[Rule]", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{"{", 
                RowBox[{"1775", ",", "aa"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"1875", ",", "bb"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"2000", ",", "cc"}], "}"}]}], "}"}]}], ",", 
            RowBox[{"gDyearsFuture", "\[Rule]", "100"}], ",", 
            RowBox[{"gDss", "\[Rule]", 
             SuperscriptBox["1.005", "25"]}], ",", 
            RowBox[{"\[Nu]", "\[Rule]", "0.33"}], ",", 
            RowBox[{"\[Delta]", "\[Rule]", 
             RowBox[{"1", "-", 
              SuperscriptBox[
               RowBox[{"(", 
                RowBox[{"1", "-", "0.1"}], ")"}], "25"]}]}], ",", 
            RowBox[{"Pie", "\[Rule]", "smoothedpieCons"}], ",", 
            RowBox[{"Piess", "\[Rule]", "0.666667"}], ",", 
            RowBox[{"lrconssh", "\[Rule]", "0.75"}], ",", 
            RowBox[{"nTypes", "\[Rule]", "10000"}], ",", 
            RowBox[{"precision", "\[Rule]", "100"}], ",", 
            RowBox[{"inityear", "\[Rule]", "1300"}], ",", 
            RowBox[{"currentyear", "\[Rule]", "2000"}], ",", " ", 
            RowBox[{"time", "\[Rule]", "200"}], ",", 
            RowBox[{"\[Omega]", "\[Rule]", "0"}], ",", 
            RowBox[{"Pie28", "\[Rule]", 
             RowBox[{"smoothedpieCons", "[", 
              RowBox[{"[", "29", "]"}], "]"}]}]}], "}"}]}], ";"}], "*)"}], 
       "\[IndentingNewLine]", "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{
         RowBox[{"inputData", "=", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"lrintr", "\[Rule]", "0.064"}], ",", 
            RowBox[{"matchlrirBaselinyears", "\[Rule]", "100"}], ",", 
            RowBox[{"stdevbeta", "\[Rule]", "0.0053"}], ",", 
            RowBox[{"gNCutoffs", "\[Rule]", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{"{", 
                RowBox[{"1700", ",", "1.030615194"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"1875", ",", "1.118744119"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"2000", ",", "1.356358323"}], "}"}]}], "}"}]}], ",", 
            RowBox[{"gNyearsFuture", "\[Rule]", "100"}], ",", 
            RowBox[{"gNss", "\[Rule]", 
             SuperscriptBox["0.99", "25"]}], ",", 
            RowBox[{"gDCutoffs", "\[Rule]", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{"{", 
                RowBox[{"1775", ",", "aa"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"1875", ",", "bb"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"2000", ",", "cc"}], "}"}]}], "}"}]}], ",", 
            RowBox[{"gDyearsFuture", "\[Rule]", "100"}], ",", 
            RowBox[{"gDss", "\[Rule]", 
             SuperscriptBox["1.005", "25"]}], ",", 
            RowBox[{"\[Nu]", "\[Rule]", "0.33"}], ",", 
            RowBox[{"\[Delta]", "\[Rule]", 
             RowBox[{"1", "-", 
              SuperscriptBox[
               RowBox[{"(", 
                RowBox[{"1", "-", "0.1"}], ")"}], "25"]}]}], ",", 
            RowBox[{"Pie", "\[Rule]", "smoothedpieCons"}], ",", 
            RowBox[{"Piess", "\[Rule]", "0.666667"}], ",", 
            RowBox[{"lrconssh", "\[Rule]", "0.75"}], ",", 
            RowBox[{"nTypes", "\[Rule]", "10000"}], ",", 
            RowBox[{"precision", "\[Rule]", "10"}], ",", 
            RowBox[{"inityear", "\[Rule]", "1300"}], ",", 
            RowBox[{"currentyear", "\[Rule]", "2000"}], ",", " ", 
            RowBox[{"time", "\[Rule]", "40"}], ",", 
            RowBox[{"\[Omega]", "\[Rule]", "0"}], ",", 
            RowBox[{"Pie28", "\[Rule]", 
             RowBox[{"smoothedpieCons", "[", 
              RowBox[{"[", "30", "]"}], "]"}]}]}], "}"}]}], ";"}], "*)"}], 
       "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"inputData", "=", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
           RowBox[{
           "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], 
           ",", 
           RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
           RowBox[{"gNCutoffs", "\[Rule]", "gNCutoffsparms"}], ",", 
           RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
           RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
           RowBox[{"gDCutoffs", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{
              RowBox[{"{", 
               RowBox[{"1775", ",", "aa"}], "}"}], ",", 
              RowBox[{"{", 
               RowBox[{"1875", ",", "bb"}], "}"}], ",", 
              RowBox[{"{", 
               RowBox[{"2000", ",", "cc"}], "}"}]}], "}"}]}], ",", 
           RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
           RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
           RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
           RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
           RowBox[{"Pie", "\[Rule]", "smoothedpieCons"}], ",", 
           RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
           RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
           RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
           RowBox[{"precision", "\[Rule]", "10"}], ",", 
           RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
           RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
           RowBox[{"time", "\[Rule]", "40"}], ",", 
           RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
           RowBox[{"Pie28", "\[Rule]", 
            RowBox[{"smoothedpieCons", "[", 
             RowBox[{"[", "30", "]"}], "]"}]}], ",", 
           RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
           RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"allParms", "=", 
         RowBox[{"calibration", "[", "inputData", "]"}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"points", "=", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"inityear", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"inityear", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"currentyear", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"currentyear", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Delta]", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"\[Delta]", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"eNdata", "\[Rule]", 
            RowBox[{
             RowBox[{"(", 
              RowBox[{"Nm1", "/.", "allParms"}], ")"}], "*", 
             RowBox[{
              RowBox[{"Quiet", "[", 
               RowBox[{"smoothedLevelsFromGrowth", "[", 
                RowBox[{
                 RowBox[{"(", 
                  RowBox[{"gNCutoffs", "/.", "inputData"}], ")"}], ",", 
                 RowBox[{
                  RowBox[{"(", 
                   RowBox[{"inityear", "/.", "inputData"}], ")"}], "-", 
                  "25"}], ",", 
                 RowBox[{
                  RowBox[{"(", 
                   RowBox[{"currentyear", "+", "gNyearsFuture"}], ")"}], "/.",
                   "inputData"}]}], "]"}], "]"}], "[", 
              RowBox[{"[", 
               RowBox[{"All", ",", "2"}], "]"}], "]"}]}]}], ",", 
           RowBox[{"gNss", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"gNss", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"Dee", "\[Rule]", 
            RowBox[{
             RowBox[{"Quiet", "[", 
              RowBox[{"smoothedLevelsFromGrowth", "[", 
               RowBox[{
                RowBox[{"(", 
                 RowBox[{"gDCutoffs", "/.", "inputData"}], ")"}], ",", 
                RowBox[{
                 RowBox[{"(", 
                  RowBox[{"inityear", "/.", "inputData"}], ")"}], "-", "25"}],
                 ",", 
                RowBox[{
                 RowBox[{"(", 
                  RowBox[{"currentyear", "+", "gDyearsFuture"}], ")"}], "/.", 
                 "inputData"}]}], "]"}], "]"}], "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
           RowBox[{"grDee", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"gDss", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Nu]", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"\[Nu]", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Alpha]", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"\[Alpha]", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"Pie", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"Pie", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"Piess", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"Piess", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Omega]", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"\[Omega]", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"time", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"time", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Beta]", "\[Rule]", 
            RowBox[{"initialDistributionConsProb", "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", "1"}], "]"}], "]"}]}], ",", 
           RowBox[{"propN", "\[Rule]", 
            RowBox[{"initialDistributionConsProb", "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
           RowBox[{
            SubscriptBox["ktilde", 
             RowBox[{"-", "1"}]], "\[Rule]", 
            SubscriptBox["ktilde", "0"]}], ",", 
           RowBox[{"precision", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"precision", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"percentiles", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"percentiles", "/.", "allParms"}], ")"}]}]}], "}"}]}], 
        ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"points2", "=", 
         RowBox[{"Join", "[", 
          RowBox[{"points", ",", 
           RowBox[{"{", 
            RowBox[{"initpoints", "\[Rule]", "initpointsx"}], "}"}]}], 
          "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"ans5", "=", 
         RowBox[{"SolveModel", "[", "points2", "]"}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"grrates", "=", 
           RowBox[{"{", 
            RowBox[{
             RowBox[{"Median", "[", 
              RowBox[{
               RowBox[{
                RowBox[{"Table", "[", 
                 RowBox[{
                  RowBox[{"{", 
                   RowBox[{
                    RowBox[{
                    RowBox[{"t", "*", "25"}], "+", "1300"}], ",", 
                    RowBox[{
                    FractionBox[
                    RowBox[{"Rest", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}], 
                    
                    RowBox[{"Most", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}]],
                     "[", 
                    RowBox[{"[", "t", "]"}], "]"}]}], "}"}], ",", 
                  RowBox[{"{", 
                   RowBox[{"t", ",", "1", ",", "29"}], "}"}]}], "]"}], "[", 
                RowBox[{"[", 
                 RowBox[{"1", ";;", "19"}], "]"}], "]"}], "[", 
               RowBox[{"[", 
                RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], ",", 
             RowBox[{"Median", "[", 
              RowBox[{
               RowBox[{
                RowBox[{"Table", "[", 
                 RowBox[{
                  RowBox[{"{", 
                   RowBox[{
                    RowBox[{
                    RowBox[{"t", "*", "25"}], "+", "1300"}], ",", 
                    RowBox[{
                    FractionBox[
                    RowBox[{"Rest", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}], 
                    
                    RowBox[{"Most", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}]],
                     "[", 
                    RowBox[{"[", "t", "]"}], "]"}]}], "}"}], ",", 
                  RowBox[{"{", 
                   RowBox[{"t", ",", "1", ",", "29"}], "}"}]}], "]"}], "[", 
                RowBox[{"[", 
                 RowBox[{"20", ";;", "23"}], "]"}], "]"}], "[", 
               RowBox[{"[", 
                RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], ",", 
             RowBox[{"Median", "[", 
              RowBox[{
               RowBox[{
                RowBox[{"Table", "[", 
                 RowBox[{
                  RowBox[{"{", 
                   RowBox[{
                    RowBox[{
                    RowBox[{"t", "*", "25"}], "+", "1300"}], ",", 
                    RowBox[{
                    FractionBox[
                    RowBox[{"Rest", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}], 
                    
                    RowBox[{"Most", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}]],
                     "[", 
                    RowBox[{"[", "t", "]"}], "]"}]}], "}"}], ",", 
                  RowBox[{"{", 
                   RowBox[{"t", ",", "1", ",", "29"}], "}"}]}], "]"}], "[", 
                RowBox[{"[", 
                 RowBox[{"24", ";;", "28"}], "]"}], "]"}], "[", 
               RowBox[{"[", 
                RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], "}"}]}], 
          ";"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"grrates", "=", 
         RowBox[{"{", 
          RowBox[{
           SuperscriptBox[
            RowBox[{"(", 
             FractionBox[
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "21", "]"}], "]"}], 
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "1", "]"}], "]"}]], ")"}], 
            FractionBox["25", 
             RowBox[{"1775", "-", "1275"}]]], ",", 
           SuperscriptBox[
            RowBox[{"(", 
             FractionBox[
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "25", "]"}], "]"}], 
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "21", "]"}], "]"}]], ")"}], 
            FractionBox["25", 
             RowBox[{"1875", "-", "1775"}]]], ",", 
           SuperscriptBox[
            RowBox[{"(", 
             FractionBox[
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "30", "]"}], "]"}], 
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "25", "]"}], "]"}]], ")"}], 
            FractionBox["25", 
             RowBox[{"2000", "-", "1875"}]]]}], "}"}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"Remove", "[", 
         RowBox[{"inputData", ",", "ans5"}], "]"}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"Return", "[", "grrates", "]"}], ";"}]}], 
      "\[IndentingNewLine]", "]"}]}]}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]"}], "Input",
 CellGroupingRules->{"GroupTogetherGrouping", 10001.},
 CellChangeTimes->{
  3.8635177655655537`*^9, {3.8637735974806013`*^9, 3.8637735976829696`*^9}, 
   3.865070714203122*^9, {3.865395309281442*^9, 3.8653953107423983`*^9}, {
   3.865395462021286*^9, 3.865395462131199*^9}, {3.8656870658341837`*^9, 
   3.8656870703479414`*^9}, 3.8663664802955713`*^9, {3.8944301612940893`*^9, 
   3.8944301785293417`*^9}, {3.894430429390369*^9, 3.894430504315989*^9}, {
   3.8944308064806347`*^9, 3.894430812794558*^9}, 3.8944310584922333`*^9, {
   3.8944311167966413`*^9, 3.894431138939095*^9}, {3.89443145160601*^9, 
   3.89443149328722*^9}, {3.8944323614635143`*^9, 3.894432361848316*^9}, {
   3.8944324318921213`*^9, 3.89443245408702*^9}, {3.894432723227734*^9, 
   3.894432753127657*^9}, {3.894432986196177*^9, 3.8944329971599216`*^9}, {
   3.894433210133746*^9, 3.894433221141823*^9}, {3.894433493868105*^9, 
   3.894433505262285*^9}, {3.894433723820862*^9, 3.894433743604007*^9}, {
   3.894433961318585*^9, 3.894433982576827*^9}, {3.894434214450403*^9, 
   3.894434234009416*^9}, {3.89443449397114*^9, 3.894434501244528*^9}, {
   3.8944347286086063`*^9, 3.894434743316289*^9}, {3.894434968045705*^9, 
   3.894434985060224*^9}, {3.894435181181389*^9, 3.894435193681978*^9}, {
   3.894435392759449*^9, 3.894435402814197*^9}, {3.894435744155819*^9, 
   3.894435757871173*^9}, {3.8944359616177464`*^9, 3.89443596762703*^9}, {
   3.894436219767043*^9, 3.8944362260974693`*^9}, 3.8949666304579353`*^9, {
   3.894967251945449*^9, 3.894967252225835*^9}, {3.8949673125995483`*^9, 
   3.894967433281789*^9}, {3.894967648786211*^9, 3.894967658145582*^9}, {
   3.894980206447342*^9, 3.894980216160246*^9}, 3.894980616679845*^9, {
   3.896151193436819*^9, 3.8961512089905*^9}, 3.8961524642683783`*^9, 
   3.896152756502841*^9, {3.896167539394092*^9, 3.8961675436359158`*^9}, {
   3.8961677812828007`*^9, 3.8961677817596493`*^9}, {3.8961685618901997`*^9, 
   3.896168625625434*^9}, 3.8961765245842123`*^9, 3.89617712690278*^9, 
   3.896177164750903*^9, {3.896189240375902*^9, 3.896189256836794*^9}, {
   3.896237783818182*^9, 3.896237784030299*^9}, {3.896246715405712*^9, 
   3.8962467207888823`*^9}, 3.896246862690405*^9, {3.896246949357946*^9, 
   3.896246950456853*^9}, {3.8962470261221743`*^9, 3.896247028426524*^9}, {
   3.8962479736583967`*^9, 3.89624797576932*^9}, 3.8962481637003307`*^9, 
   3.896248360804446*^9, {3.896248865166951*^9, 3.896248865638084*^9}, 
   3.8962489732404413`*^9, 3.896249510135578*^9, 3.896253297553278*^9, {
   3.896253353174135*^9, 3.896253363515573*^9}, {3.896253420007099*^9, 
   3.896253420052924*^9}, {3.896253475365512*^9, 3.896253477957603*^9}, {
   3.896253528839517*^9, 3.896253530364293*^9}, {3.896253592132263*^9, 
   3.8962535949074306`*^9}, 3.896254411598815*^9, {3.896259543507779*^9, 
   3.8962595548184233`*^9}, {3.896259604875214*^9, 3.896259605042103*^9}, 
   3.896259641284771*^9, {3.896260851744389*^9, 3.8962608520239058`*^9}, {
   3.89626099388616*^9, 3.896260993930797*^9}, {3.896261029059024*^9, 
   3.896261029118433*^9}, {3.896261412289307*^9, 3.8962614123961573`*^9}, {
   3.896261476361484*^9, 3.896261504748332*^9}, {3.896261884296034*^9, 
   3.8962618934798183`*^9}, {3.896852907824437*^9, 3.896852919592903*^9}, {
   3.896853088687676*^9, 3.896853107163468*^9}, {3.896853214543079*^9, 
   3.896853277403655*^9}, {3.8968535761661654`*^9, 3.896853576840423*^9}, 
   3.896853706890362*^9, {3.89685471488765*^9, 3.896854776263294*^9}, {
   3.8968548535091133`*^9, 3.896854869106722*^9}, 3.8968553452232857`*^9, {
   3.896855596371025*^9, 3.89685559646996*^9}, 3.896922447608083*^9, 
   3.896928491589931*^9, {3.896933835165987*^9, 3.896933840142089*^9}, 
   3.896937320528051*^9, 3.8969373654973097`*^9, {3.896937468236788*^9, 
   3.896937468403767*^9}, {3.8969375878658447`*^9, 3.896937616724633*^9}, 
   3.8969388210587263`*^9, {3.896938975785695*^9, 3.896938978807228*^9}, 
   3.896944038829331*^9, {3.896952509137546*^9, 3.89695254894503*^9}, {
   3.8969526150933037`*^9, 3.896952665029254*^9}, {3.8969527551696663`*^9, 
   3.896952766020742*^9}, {3.896952802707855*^9, 3.896952804791223*^9}, {
   3.896953707959491*^9, 3.896953719779747*^9}, {3.897022892309791*^9, 
   3.897022892439385*^9}, {3.897024168317601*^9, 3.897024174213448*^9}, {
   3.898766686859886*^9, 3.898766688734668*^9}, {3.898766723171637*^9, 
   3.8987667234399*^9}, {3.898766990879383*^9, 3.898767038801669*^9}, 
   3.898836926128664*^9, {3.898839127008255*^9, 3.8988391643023663`*^9}, {
   3.8988392117969227`*^9, 3.898839255612749*^9}, {3.8988393891194696`*^9, 
   3.898839391076767*^9}, {3.8988396853240147`*^9, 3.898839700498077*^9}, {
   3.898839820241065*^9, 3.89883982036796*^9}, {3.8988425131712303`*^9, 
   3.898842527494775*^9}, {3.8988425609887543`*^9, 3.8988425699613323`*^9}, {
   3.89979426782799*^9, 3.8997942679313793`*^9}, {3.899794321319622*^9, 
   3.8997943225690727`*^9}, {3.9029908610740643`*^9, 3.902990951561676*^9}, {
   3.90299201189223*^9, 3.902992015719812*^9}, 3.902995755394566*^9},
 CellLabel->"In[28]:=",ExpressionUUID->"74560a61-b829-4f5d-ae09-9fa335c4530e"]
}, Closed]],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{
   RowBox[{"Below", " ", "we", " ", "re"}], "-", 
   RowBox[{
   "calibrate", " ", "the", " ", "productivity", " ", "growths", " ", "to", 
    " ", "match", " ", "gdp", " ", "per", " ", "capita", " ", "growth", " ", 
    "rates"}]}], "*)"}]], "Input",
 CellChangeTimes->{{3.8969380814190283`*^9, 3.896938093872334*^9}},
 CellLabel->"In[24]:=",ExpressionUUID->"6ec84d96-93c2-4890-a0b3-de5ecd1c86bc"],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"LaunchKernels", "[", "5", "]"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"initialPoint", "=", 
    RowBox[{"{", 
     RowBox[{
     "0.9867871259223387`", ",", "1.0868202267281502`", ",", 
      "1.3274672838428865`"}], "}"}]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{"Initial", " ", "guess", " ", "for", " ", "the", " ", "point"}], 
   "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"gridDensity", "=", 
    RowBox[{"{", 
     RowBox[{"5", ",", "5", ",", "5"}], "}"}]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{
   "Number", " ", "of", " ", "grid", " ", "points", " ", "for", " ", "each", 
    " ", "dimension"}], "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"del", "=", 
    RowBox[{"{", 
     RowBox[{"0.01", ",", "0.01", ",", "0.01"}], "}"}]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{
   "Initial", " ", "search", " ", "interval", " ", "size", " ", "for", " ", 
    "each", " ", "dimension"}], "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"target", "=", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{"gYCutoffstarget", "[", 
       RowBox[{"[", 
        RowBox[{"1", ",", "2"}], "]"}], "]"}], ",", 
      RowBox[{"gYCutoffstarget", "[", 
       RowBox[{"[", 
        RowBox[{"2", ",", "2"}], "]"}], "]"}], ",", 
      RowBox[{"gYCutoffstarget", "[", 
       RowBox[{"[", 
        RowBox[{"3", ",", "2"}], "]"}], "]"}]}], "}"}]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{"Target", " ", "value", " ", "to", " ", "approach"}], 
   "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"tolerance", "=", 
    SuperscriptBox["10", 
     RowBox[{"-", "7"}]]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{
   "Desired", " ", "Euclidean", " ", "distance", " ", "from", " ", "target", 
    " ", "to", " ", "stop", " ", "iterations"}], 
   "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{"AbsoluteTiming", "[", 
  RowBox[{
   RowBox[{"optimizedProductivities", "=", 
    RowBox[{"IterativeFindMinPoint", "[", 
     RowBox[{
     "initialPoint", ",", "gridDensity", ",", "del", ",", "target", ",", 
      "tolerance", ",", "testansConsProb"}], "]"}]}], ";"}], 
  "]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"CloseKernels", "[", "]"}], ";"}]}], "Input",
 CellChangeTimes->{
  3.902995868071032*^9, {3.90299602734475*^9, 3.90299603279677*^9}, {
   3.902999536374345*^9, 3.902999553333618*^9}, {3.903007746050776*^9, 
   3.903007764596962*^9}},ExpressionUUID->"da9a9949-171b-4467-8831-\
998576f31df8"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"2.227551`", ",", "Null"}], "}"}]], "Output",
 CellChangeTimes->{3.90299582883112*^9, 3.902995987063087*^9, 
  3.902999500071334*^9, 3.902999557777033*^9},
 CellLabel->"Out[47]=",ExpressionUUID->"318d1276-c177-48bf-88df-b4cee19fdacb"]
}, Open  ]],

Cell[BoxData[
 RowBox[{
  RowBox[{"inputDataConsProb", "=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
     RowBox[{
     "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], ",", 
     RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
     RowBox[{"gNCutoffs", "\[Rule]", "gNCutoffsparms"}], ",", 
     RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
     RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
     RowBox[{"gDCutoffs", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"1775", ",", 
          RowBox[{"optimizedProductivities", "[", 
           RowBox[{"[", 
            RowBox[{"1", ",", "1"}], "]"}], "]"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"1875", ",", 
          RowBox[{"optimizedProductivities", "[", 
           RowBox[{"[", 
            RowBox[{"1", ",", "2"}], "]"}], "]"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"2000", ",", 
          RowBox[{"optimizedProductivities", "[", 
           RowBox[{"[", 
            RowBox[{"1", ",", "3"}], "]"}], "]"}]}], "}"}]}], "}"}]}], ",", 
     RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
     RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
     RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
     RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
     RowBox[{"Pie", "\[Rule]", "smoothedpieCons"}], ",", 
     RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
     RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
     RowBox[{"precision", "\[Rule]", "precisionparm"}], ",", 
     RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
     RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
     RowBox[{"time", "\[Rule]", "timeparm"}], ",", 
     RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
     RowBox[{"Pie28", "\[Rule]", 
      RowBox[{"smoothedpieCons", "[", 
       RowBox[{"[", "30", "]"}], "]"}]}], ",", 
     RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
     RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.902991959267942*^9, 3.902991971509049*^9}, 
   3.902996112542053*^9},
 CellLabel->"In[49]:=",ExpressionUUID->"2c013c77-694a-4045-9ae8-750b0072b7db"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"{", 
    RowBox[{
    "initialDistributionConsProb", ",", "allParmsConsProb", ",", 
     "averageBeta2000ConsProb"}], "}"}], "=", 
   RowBox[{"findInitialDistributionHelper", "[", "inputDataConsProb", "]"}]}],
   ";"}]], "Input",
 CellChangeTimes->{{3.8988437851302643`*^9, 3.89884380418405*^9}, {
  3.899794712285202*^9, 3.899794726169072*^9}},
 CellLabel->"In[50]:=",ExpressionUUID->"550baca7-3f9a-4dfb-bf30-bd8ce2e9d941"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ansConsProb", "=", 
   RowBox[{"solveModelHelper", "[", 
    RowBox[{
    "inputDataConsProb", ",", "initpointsx", ",", 
     "initialDistributionConsProb", ",", "allParmsConsProb"}], "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{
  3.896953853944868*^9, {3.8988437735272617`*^9, 3.898843773662134*^9}, {
   3.898843808828148*^9, 3.89884381570503*^9}, {3.899794738032811*^9, 
   3.89979474473705*^9}},
 CellLabel->"In[51]:=",ExpressionUUID->"c8812f27-e91f-48e8-a1e1-cf223250f3cf"],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{"--", 
   RowBox[{"--", 
    RowBox[{"--", 
     RowBox[{"--", 
      RowBox[{"--", "--"}]}]}]}]}], "*)"}]], "Input",
 CellChangeTimes->{{3.896934784371644*^9, 3.896934785665431*^9}, {
  3.902728665417498*^9, 3.902728667112173*^9}},
 CellLabel->"In[33]:=",ExpressionUUID->"fe541328-63fd-4d33-9537-056bfbb689c1"],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{"Fixed", " ", 
   RowBox[{
    RowBox[{
     SubscriptBox["gN", "t"], " ", "--"}], "--"}], " ", "Full", " ", 
   "Model"}], "*)"}]], "Input",
 CellChangeTimes->{{3.902728669007627*^9, 3.9027286713404617`*^9}},
 CellLabel->"In[34]:=",ExpressionUUID->"1da176df-60e6-407a-9b1d-d34cae379d02"],

Cell[BoxData[
 RowBox[{
  RowBox[{"inputDataConsPop", "=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
     RowBox[{
     "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], ",", 
     RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
     RowBox[{"gNCutoffs", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"1775", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"1875", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"2000", ",", "1"}], "}"}]}], "}"}]}], ",", 
     RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
     RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
     RowBox[{"gDCutoffs", "\[Rule]", "gDCutoffsparm"}], ",", 
     RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
     RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
     RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
     RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
     RowBox[{"Pie", "\[Rule]", 
      RowBox[{"smoothedpie", "[", 
       RowBox[{"[", 
        RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
     RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
     RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
     RowBox[{"precision", "\[Rule]", "precisionparm"}], ",", 
     RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
     RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
     RowBox[{"time", "\[Rule]", "timeparm"}], ",", 
     RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
     RowBox[{"Pie28", "\[Rule]", 
      RowBox[{"smoothedpie", "[", 
       RowBox[{"[", 
        RowBox[{"30", ",", "2"}], "]"}], "]"}]}], ",", 
     RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
     RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.902996303040668*^9, 3.902996319089273*^9}},
 CellLabel->
  "In[124]:=",ExpressionUUID->"8a6eff8e-573d-4cce-8335-727b41499ec4"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"{", 
    RowBox[{
    "initialDistributionConsPop", ",", "allParmsConsConsPop", ",", 
     "averageBeta2000ConsPop"}], "}"}], "=", 
   RowBox[{"findInitialDistributionHelper", "[", "inputDataConsPop", "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.898844663963498*^9, 3.898844697758171*^9}, 
   3.898844903203454*^9, {3.899795121017191*^9, 3.8997951263969517`*^9}},
 CellLabel->
  "In[125]:=",ExpressionUUID->"680a5b4c-3e77-40d8-803b-627aec0e40b9"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ansConsPop", "=", 
   RowBox[{"solveModelHelper", "[", 
    RowBox[{
    "inputDataConsPop", ",", "initpointsFull", ",", 
     "initialDistributionConsPop", ",", "allParmsConsConsPop"}], "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{
  3.898844635006713*^9, {3.899795133438908*^9, 3.8997951522440653`*^9}, 
   3.8997957562279243`*^9},
 CellLabel->
  "In[126]:=",ExpressionUUID->"92d5da0e-8478-4cab-bb4c-3d91da0b34a7"],

Cell[BoxData[
 RowBox[{
  RowBox[{"initpointsx", "=", 
   RowBox[{"Join", "[", 
    RowBox[{
     RowBox[{"ansConsPop", "[", 
      RowBox[{"[", "2", "]"}], "]"}], ",", 
     RowBox[{"ansConsPop", "[", 
      RowBox[{"[", "4", "]"}], "]"}]}], "]"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.896953464606525*^9, 3.89695347009166*^9}, {
   3.896953566366857*^9, 3.896953575989663*^9}, 3.896953877600214*^9},
 CellLabel->
  "In[127]:=",ExpressionUUID->"da0625bc-83ca-464e-9529-af8b1726fdbe"],

Cell[CellGroupData[{

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{
  "testConsPop", " ", "function", " ", "to", " ", "recalibrate", " ", "new", 
   " ", "productivity", " ", "growth", " ", 
   RowBox[{"rates", ".", " ", "Needs"}], " ", "initpointsx", " ", "to", " ", 
   "run"}], "*)"}]], "Input",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{{3.896937561517844*^9, 3.89693761672165*^9}, 
   3.896953521693509*^9, {3.896953583387587*^9, 3.8969535858452787`*^9}, 
   3.896953879198163*^9, 3.8970534106748877`*^9},
 CellLabel->
  "In[128]:=",ExpressionUUID->"ceac3605-e385-4428-8eb0-cbb67318e8ad"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"counter", "=", "0"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{
    RowBox[{"testConsPop", "[", 
     RowBox[{"aa_", ",", "bb_", ",", "cc_"}], "]"}], ":=", 
    RowBox[{
     RowBox[{"testConsPop", "[", 
      RowBox[{"aa", ",", "bb", ",", "cc"}], "]"}], "=", "\[IndentingNewLine]", 
     RowBox[{"Module", "[", 
      RowBox[{
       RowBox[{"{", 
        RowBox[{
        "inputData", ",", "allParmsOriginal", ",", "distt2000", ",", 
         "averageBeta2000", ",", "initialDistributionTilde", ",", "pp", ",", 
         "temp", ",", "points", ",", " ", "points2", ",", "ans5", ",", 
         "grrates", ",", "averageBeta2000ans5", ",", "allParmsans5", ",", 
         "ipoints", ",", "allParms"}], "}"}], ",", "\[IndentingNewLine]", 
       "\[IndentingNewLine]", "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{
         RowBox[{"inputData", "=", 
          RowBox[{"{", 
           RowBox[{
            RowBox[{"lrintr", "\[Rule]", "0.064"}], ",", 
            RowBox[{"matchlrirBaselinyears", "\[Rule]", "100"}], ",", 
            RowBox[{"stdevbeta", "\[Rule]", "0.0053"}], ",", 
            RowBox[{"gNCutoffs", "\[Rule]", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{"{", 
                RowBox[{"1775", ",", "1"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"1875", ",", "1"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"2000", ",", "1"}], "}"}]}], "}"}]}], ",", 
            RowBox[{"gNyearsFuture", "\[Rule]", "100"}], ",", 
            RowBox[{"gNss", "\[Rule]", 
             SuperscriptBox["0.99", "25"]}], ",", 
            RowBox[{"gDCutoffs", "\[Rule]", 
             RowBox[{"{", 
              RowBox[{
               RowBox[{"{", 
                RowBox[{"1775", ",", "aa"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"1875", ",", "bb"}], "}"}], ",", 
               RowBox[{"{", 
                RowBox[{"2000", ",", "cc"}], "}"}]}], "}"}]}], ",", 
            RowBox[{"gDyearsFuture", "\[Rule]", "100"}], ",", 
            RowBox[{"gDss", "\[Rule]", 
             SuperscriptBox["1.005", "25"]}], ",", 
            RowBox[{"\[Nu]", "\[Rule]", "0.33"}], ",", 
            RowBox[{"\[Delta]", "\[Rule]", 
             RowBox[{"1", "-", 
              SuperscriptBox[
               RowBox[{"(", 
                RowBox[{"1", "-", "0.1"}], ")"}], "25"]}]}], ",", 
            RowBox[{"Pie", "\[Rule]", 
             RowBox[{"smoothedpie", "[", 
              RowBox[{"[", 
               RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
            RowBox[{"Piess", "\[Rule]", "0.666667"}], ",", 
            RowBox[{"lrconssh", "\[Rule]", "0.75"}], ",", 
            RowBox[{"nTypes", "\[Rule]", "10000"}], ",", 
            RowBox[{"precision", "\[Rule]", "10"}], ",", 
            RowBox[{"inityear", "\[Rule]", "1300"}], ",", 
            RowBox[{"currentyear", "\[Rule]", "2000"}], ",", " ", 
            RowBox[{"time", "\[Rule]", "40"}], ",", 
            RowBox[{"\[Omega]", "\[Rule]", "0"}], ",", 
            RowBox[{"Pie28", "\[Rule]", 
             RowBox[{"smoothedpie", "[", 
              RowBox[{"[", 
               RowBox[{"30", ",", "2"}], "]"}], "]"}]}]}], "}"}]}], ";"}], 
        "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
       "\[IndentingNewLine]", 
       RowBox[{
        RowBox[{"inputData", "=", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
           RowBox[{
           "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], 
           ",", 
           RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
           RowBox[{"gNCutoffs", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{
              RowBox[{"{", 
               RowBox[{"1775", ",", "1"}], "}"}], ",", 
              RowBox[{"{", 
               RowBox[{"1875", ",", "1"}], "}"}], ",", 
              RowBox[{"{", 
               RowBox[{"2000", ",", "1"}], "}"}]}], "}"}]}], ",", 
           RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
           RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
           RowBox[{"gDCutoffs", "\[Rule]", 
            RowBox[{"{", 
             RowBox[{
              RowBox[{"{", 
               RowBox[{"1775", ",", "aa"}], "}"}], ",", 
              RowBox[{"{", 
               RowBox[{"1875", ",", "bb"}], "}"}], ",", 
              RowBox[{"{", 
               RowBox[{"2000", ",", "cc"}], "}"}]}], "}"}]}], ",", 
           RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
           RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
           RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
           RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
           RowBox[{"Pie", "\[Rule]", 
            RowBox[{"smoothedpie", "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
           RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
           RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
           RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
           RowBox[{"precision", "\[Rule]", "10"}], ",", 
           RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
           RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
           RowBox[{"time", "\[Rule]", "40"}], ",", 
           RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
           RowBox[{"Pie28", "\[Rule]", 
            RowBox[{"smoothedpie", "[", 
             RowBox[{"[", 
              RowBox[{"30", ",", "2"}], "]"}], "]"}]}], ",", 
           RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
           RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"allParms", "=", 
         RowBox[{"calibration", "[", "inputData", "]"}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", 
        RowBox[{"points", "=", 
         RowBox[{"{", 
          RowBox[{
           RowBox[{"inityear", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"inityear", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"currentyear", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"currentyear", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Delta]", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"\[Delta]", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"eNdata", "\[Rule]", 
            RowBox[{
             RowBox[{"(", 
              RowBox[{"Nm1", "/.", "allParms"}], ")"}], "*", 
             RowBox[{
              RowBox[{"Quiet", "[", 
               RowBox[{"smoothedLevelsFromGrowth", "[", 
                RowBox[{
                 RowBox[{"(", 
                  RowBox[{"gNCutoffs", "/.", "inputData"}], ")"}], ",", 
                 RowBox[{
                  RowBox[{"(", 
                   RowBox[{"inityear", "/.", "inputData"}], ")"}], "-", 
                  "25"}], ",", 
                 RowBox[{
                  RowBox[{"(", 
                   RowBox[{"currentyear", "+", "gNyearsFuture"}], ")"}], "/.",
                   "inputData"}]}], "]"}], "]"}], "[", 
              RowBox[{"[", 
               RowBox[{"All", ",", "2"}], "]"}], "]"}]}]}], ",", 
           RowBox[{"gNss", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"gNss", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"Dee", "\[Rule]", 
            RowBox[{
             RowBox[{"Quiet", "[", 
              RowBox[{"smoothedLevelsFromGrowth", "[", 
               RowBox[{
                RowBox[{"(", 
                 RowBox[{"gDCutoffs", "/.", "inputData"}], ")"}], ",", 
                RowBox[{
                 RowBox[{"(", 
                  RowBox[{"inityear", "/.", "inputData"}], ")"}], "-", "25"}],
                 ",", 
                RowBox[{
                 RowBox[{"(", 
                  RowBox[{"currentyear", "+", "gDyearsFuture"}], ")"}], "/.", 
                 "inputData"}]}], "]"}], "]"}], "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
           RowBox[{"grDee", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"gDss", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Nu]", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"\[Nu]", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Alpha]", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"\[Alpha]", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"Pie", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"Pie", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"Piess", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"Piess", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Omega]", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"\[Omega]", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"time", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"time", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"\[Beta]", "\[Rule]", 
            RowBox[{"initialDistributionConsPop", "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", "1"}], "]"}], "]"}]}], ",", 
           RowBox[{"propN", "\[Rule]", 
            RowBox[{"initialDistributionConsPop", "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
           RowBox[{
            SubscriptBox["ktilde", 
             RowBox[{"-", "1"}]], "\[Rule]", 
            SubscriptBox["ktilde", "0"]}], ",", 
           RowBox[{"precision", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"precision", "/.", "allParms"}], ")"}]}], ",", 
           RowBox[{"percentiles", "\[Rule]", 
            RowBox[{"(", 
             RowBox[{"percentiles", "/.", "allParms"}], ")"}]}]}], "}"}]}], 
        ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"points2", "=", 
         RowBox[{"Join", "[", 
          RowBox[{"points", ",", 
           RowBox[{"{", 
            RowBox[{"initpoints", "\[Rule]", "initpointsx"}], "}"}]}], 
          "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"ans5", "=", 
         RowBox[{"SolveModel", "[", "points2", "]"}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"(*", 
         RowBox[{
          RowBox[{"grrates", "=", 
           RowBox[{"{", 
            RowBox[{
             RowBox[{"Median", "[", 
              RowBox[{
               RowBox[{
                RowBox[{"Table", "[", 
                 RowBox[{
                  RowBox[{"{", 
                   RowBox[{
                    RowBox[{
                    RowBox[{"t", "*", "25"}], "+", "1300"}], ",", 
                    RowBox[{
                    FractionBox[
                    RowBox[{"Rest", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}], 
                    
                    RowBox[{"Most", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}]],
                     "[", 
                    RowBox[{"[", "t", "]"}], "]"}]}], "}"}], ",", 
                  RowBox[{"{", 
                   RowBox[{"t", ",", "1", ",", "29"}], "}"}]}], "]"}], "[", 
                RowBox[{"[", 
                 RowBox[{"1", ";;", "19"}], "]"}], "]"}], "[", 
               RowBox[{"[", 
                RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], ",", 
             RowBox[{"Median", "[", 
              RowBox[{
               RowBox[{
                RowBox[{"Table", "[", 
                 RowBox[{
                  RowBox[{"{", 
                   RowBox[{
                    RowBox[{
                    RowBox[{"t", "*", "25"}], "+", "1300"}], ",", 
                    RowBox[{
                    FractionBox[
                    RowBox[{"Rest", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}], 
                    
                    RowBox[{"Most", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}]],
                     "[", 
                    RowBox[{"[", "t", "]"}], "]"}]}], "}"}], ",", 
                  RowBox[{"{", 
                   RowBox[{"t", ",", "1", ",", "29"}], "}"}]}], "]"}], "[", 
                RowBox[{"[", 
                 RowBox[{"20", ";;", "23"}], "]"}], "]"}], "[", 
               RowBox[{"[", 
                RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}], ",", 
             RowBox[{"Median", "[", 
              RowBox[{
               RowBox[{
                RowBox[{"Table", "[", 
                 RowBox[{
                  RowBox[{"{", 
                   RowBox[{
                    RowBox[{
                    RowBox[{"t", "*", "25"}], "+", "1300"}], ",", 
                    RowBox[{
                    FractionBox[
                    RowBox[{"Rest", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}], 
                    
                    RowBox[{"Most", "[", 
                    RowBox[{"ans5", "[", 
                    RowBox[{"[", 
                    RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "]"}]],
                     "[", 
                    RowBox[{"[", "t", "]"}], "]"}]}], "}"}], ",", 
                  RowBox[{"{", 
                   RowBox[{"t", ",", "1", ",", "29"}], "}"}]}], "]"}], "[", 
                RowBox[{"[", 
                 RowBox[{"24", ";;", "28"}], "]"}], "]"}], "[", 
               RowBox[{"[", 
                RowBox[{"All", ",", "2"}], "]"}], "]"}], "]"}]}], "}"}]}], 
          ";"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"grrates", "=", 
         RowBox[{"{", 
          RowBox[{
           SuperscriptBox[
            RowBox[{"(", 
             FractionBox[
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "21", "]"}], "]"}], 
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "1", "]"}], "]"}]], ")"}], 
            FractionBox["25", 
             RowBox[{"1775", "-", "1275"}]]], ",", 
           SuperscriptBox[
            RowBox[{"(", 
             FractionBox[
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "25", "]"}], "]"}], 
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "21", "]"}], "]"}]], ")"}], 
            FractionBox["25", 
             RowBox[{"1875", "-", "1775"}]]], ",", 
           SuperscriptBox[
            RowBox[{"(", 
             FractionBox[
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "30", "]"}], "]"}], 
              RowBox[{
               RowBox[{"ans5", "[", 
                RowBox[{"[", 
                 RowBox[{"7", ",", "All", ",", "2"}], "]"}], "]"}], "[", 
               RowBox[{"[", "25", "]"}], "]"}]], ")"}], 
            FractionBox["25", 
             RowBox[{"2000", "-", "1875"}]]]}], "}"}]}], ";", 
        "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"Remove", "[", 
         RowBox[{
         "inputData", ",", "ans5", ",", "points", ",", " ", "points2"}], 
         "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", 
        RowBox[{"Return", "[", "grrates", "]"}], ";"}]}], 
      "\[IndentingNewLine]", "]"}]}]}], ";"}], 
  "\[IndentingNewLine]"}], "\[IndentingNewLine]"}], "Input",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.},
 CellChangeTimes->{
  3.8635177655655537`*^9, {3.8637735974806013`*^9, 3.8637735976829696`*^9}, 
   3.865070714203122*^9, {3.865395309281442*^9, 3.8653953107423983`*^9}, {
   3.865395462021286*^9, 3.865395462131199*^9}, {3.8656870658341837`*^9, 
   3.8656870703479414`*^9}, 3.8663664802955713`*^9, {3.8944301612940893`*^9, 
   3.8944301785293417`*^9}, {3.894430429390369*^9, 3.894430504315989*^9}, {
   3.8944308064806347`*^9, 3.894430812794558*^9}, 3.8944310584922333`*^9, {
   3.8944311167966413`*^9, 3.894431138939095*^9}, {3.89443145160601*^9, 
   3.89443149328722*^9}, {3.8944323614635143`*^9, 3.894432361848316*^9}, {
   3.8944324318921213`*^9, 3.89443245408702*^9}, {3.894432723227734*^9, 
   3.894432753127657*^9}, {3.894432986196177*^9, 3.8944329971599216`*^9}, {
   3.894433210133746*^9, 3.894433221141823*^9}, {3.894433493868105*^9, 
   3.894433505262285*^9}, {3.894433723820862*^9, 3.894433743604007*^9}, {
   3.894433961318585*^9, 3.894433982576827*^9}, {3.894434214450403*^9, 
   3.894434234009416*^9}, {3.89443449397114*^9, 3.894434501244528*^9}, {
   3.8944347286086063`*^9, 3.894434743316289*^9}, {3.894434968045705*^9, 
   3.894434985060224*^9}, {3.894435181181389*^9, 3.894435193681978*^9}, {
   3.894435392759449*^9, 3.894435402814197*^9}, {3.894435744155819*^9, 
   3.894435757871173*^9}, {3.8944359616177464`*^9, 3.89443596762703*^9}, {
   3.894436219767043*^9, 3.8944362260974693`*^9}, 3.8949666304579353`*^9, {
   3.894967251945449*^9, 3.894967252225835*^9}, {3.8949673125995483`*^9, 
   3.894967433281789*^9}, {3.894967648786211*^9, 3.894967658145582*^9}, {
   3.894980206447342*^9, 3.894980216160246*^9}, 3.894980616679845*^9, {
   3.896151193436819*^9, 3.8961512089905*^9}, 3.8961524642683783`*^9, 
   3.896152756502841*^9, {3.896167539394092*^9, 3.8961675436359158`*^9}, {
   3.8961677812828007`*^9, 3.8961677817596493`*^9}, {3.8961685618901997`*^9, 
   3.896168625625434*^9}, 3.8961765245842123`*^9, 3.89617712690278*^9, 
   3.896177164750903*^9, {3.896189240375902*^9, 3.896189256836794*^9}, {
   3.896237783818182*^9, 3.896237784030299*^9}, {3.896246715405712*^9, 
   3.8962467207888823`*^9}, 3.896246862690405*^9, {3.896246949357946*^9, 
   3.896246950456853*^9}, {3.8962470261221743`*^9, 3.896247028426524*^9}, {
   3.8962479736583967`*^9, 3.89624797576932*^9}, 3.8962481637003307`*^9, 
   3.896248360804446*^9, {3.896248865166951*^9, 3.896248865638084*^9}, 
   3.8962489732404413`*^9, 3.896249510135578*^9, 3.896253297553278*^9, {
   3.896253353174135*^9, 3.896253363515573*^9}, {3.896253420007099*^9, 
   3.896253420052924*^9}, {3.896253475365512*^9, 3.896253477957603*^9}, {
   3.896253528839517*^9, 3.896253530364293*^9}, {3.896253592132263*^9, 
   3.8962535949074306`*^9}, 3.896254411598815*^9, {3.896259543507779*^9, 
   3.8962595548184233`*^9}, {3.896259604875214*^9, 3.896259605042103*^9}, 
   3.896259641284771*^9, {3.896260851744389*^9, 3.8962608520239058`*^9}, {
   3.89626099388616*^9, 3.896260993930797*^9}, {3.896261029059024*^9, 
   3.896261029118433*^9}, {3.896261412289307*^9, 3.8962614123961573`*^9}, {
   3.896261476361484*^9, 3.896261504748332*^9}, {3.896261884296034*^9, 
   3.8962618934798183`*^9}, {3.896852907824437*^9, 3.896852919592903*^9}, {
   3.896853088687676*^9, 3.896853107163468*^9}, {3.896853214543079*^9, 
   3.896853277403655*^9}, {3.8968535761661654`*^9, 3.896853576840423*^9}, 
   3.896853706890362*^9, {3.89685471488765*^9, 3.896854776263294*^9}, {
   3.8968548535091133`*^9, 3.896854869106722*^9}, 3.8968553452232857`*^9, {
   3.896855596371025*^9, 3.89685559646996*^9}, 3.896922447608083*^9, 
   3.896928491589931*^9, {3.896933835165987*^9, 3.896933840142089*^9}, 
   3.896937320528051*^9, 3.8969373654973097`*^9, {3.896937468236788*^9, 
   3.896937468403767*^9}, {3.8969375878658447`*^9, 3.896937616724633*^9}, 
   3.8969388210587263`*^9, {3.896938975785695*^9, 3.896938978807228*^9}, 
   3.896944038829331*^9, {3.896952509137546*^9, 3.89695254894503*^9}, {
   3.8969526150933037`*^9, 3.896952665029254*^9}, {3.8969527551696663`*^9, 
   3.896952766020742*^9}, {3.896952802707855*^9, 3.896952804791223*^9}, {
   3.896953521693849*^9, 3.8969535628908243`*^9}, 3.896953885738228*^9, {
   3.8970518130229*^9, 3.897051819340982*^9}, {3.897053236935446*^9, 
   3.897053237059269*^9}, {3.8970532986843147`*^9, 3.8970533031200027`*^9}, {
   3.897053352456849*^9, 3.8970533538357697`*^9}, {3.898844973109325*^9, 
   3.89884499196424*^9}, {3.898845061503437*^9, 3.898845063978582*^9}, {
   3.89884510936075*^9, 3.8988452092478313`*^9}, {3.8988452485608587`*^9, 
   3.8988452559263487`*^9}, {3.8988452976727*^9, 3.89884531913916*^9}, {
   3.898845390945408*^9, 3.898845394901417*^9}, {3.898846296763932*^9, 
   3.898846321076017*^9}, {3.8997959857451687`*^9, 3.8997959890553837`*^9}, {
   3.902996428625692*^9, 3.902996435755863*^9}, {3.9029964687649097`*^9, 
   3.902996546415865*^9}},
 CellLabel->
  "In[129]:=",ExpressionUUID->"086b1dec-63fc-468d-8daa-c72b2fdf8960"]
}, Closed]],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{
   RowBox[{"Below", " ", "we", " ", "re"}], "-", 
   RowBox[{
   "calibrate", " ", "the", " ", "productivity", " ", "growths", " ", "to", 
    " ", "match", " ", "gdp", " ", "per", " ", "capita", " ", "growth", " ", 
    "rates"}]}], "*)"}]], "Input",
 CellChangeTimes->{{3.8969380814190283`*^9, 3.896938093872334*^9}},
 CellLabel->"In[42]:=",ExpressionUUID->"06f5af4f-370c-4081-9523-adac9a38e3a1"],

Cell[CellGroupData[{

Cell[BoxData[{
 RowBox[{
  RowBox[{"LaunchKernels", "[", "5", "]"}], ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{
   RowBox[{"initialPoint", "=", 
    RowBox[{"{", 
     RowBox[{
     "0.98677955754122`", ",", "1.0619620558145864`", ",", 
      "1.268371478541405`"}], "}"}]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{"Initial", " ", "guess", " ", "for", " ", "the", " ", "point"}], 
   "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"gridDensity", "=", 
    RowBox[{"{", 
     RowBox[{"5", ",", "5", ",", "5"}], "}"}]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{
   "Number", " ", "of", " ", "grid", " ", "points", " ", "for", " ", "each", 
    " ", "dimension"}], "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"del", "=", 
    RowBox[{"{", 
     RowBox[{"0.001", ",", "0.001", ",", "0.001"}], "}"}]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{
   "Initial", " ", "search", " ", "interval", " ", "size", " ", "for", " ", 
    "each", " ", "dimension"}], "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"target", "=", 
    RowBox[{"{", 
     RowBox[{
      RowBox[{"gYCutoffstarget", "[", 
       RowBox[{"[", 
        RowBox[{"1", ",", "2"}], "]"}], "]"}], ",", 
      RowBox[{"gYCutoffstarget", "[", 
       RowBox[{"[", 
        RowBox[{"2", ",", "2"}], "]"}], "]"}], ",", 
      RowBox[{"gYCutoffstarget", "[", 
       RowBox[{"[", 
        RowBox[{"3", ",", "2"}], "]"}], "]"}]}], "}"}]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{"Target", " ", "value", " ", "to", " ", "approach"}], 
   "*)"}]}], "\n", 
 RowBox[{
  RowBox[{
   RowBox[{"tolerance", "=", 
    SuperscriptBox["10", 
     RowBox[{"-", "7"}]]}], ";"}], " ", 
  RowBox[{"(*", 
   RowBox[{
   "Desired", " ", "Euclidean", " ", "distance", " ", "from", " ", "target", 
    " ", "to", " ", "stop", " ", "iterations"}], 
   "*)"}]}], "\[IndentingNewLine]", 
 RowBox[{"AbsoluteTiming", "[", 
  RowBox[{
   RowBox[{"optimizedProductivities", "=", 
    RowBox[{"IterativeFindMinPoint", "[", 
     RowBox[{
     "initialPoint", ",", "gridDensity", ",", "del", ",", "target", ",", 
      "tolerance", ",", "testConsPop"}], "]"}]}], ";"}], 
  "]"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"CloseKernels", "[", "]"}], ";"}]}], "Input",
 CellChangeTimes->{{3.8988457303469048`*^9, 3.8988457327267227`*^9}, {
   3.898846272641958*^9, 3.898846277843651*^9}, {3.898846998835648*^9, 
   3.898847003910904*^9}, {3.898847585707258*^9, 3.8988475977231693`*^9}, {
   3.899796494602475*^9, 3.899796506340789*^9}, 3.899796537374433*^9, {
   3.902729228624161*^9, 3.902729229716523*^9}, {3.902730942416635*^9, 
   3.9027309429109097`*^9}, {3.902731660474229*^9, 3.902731662212675*^9}, {
   3.902733171631809*^9, 3.9027331794803457`*^9}, {3.902996890895109*^9, 
   3.902996907079151*^9}, 3.902996996994169*^9, {3.902997232438472*^9, 
   3.902997238876315*^9}, {3.903007787419409*^9, 
   3.903007794557765*^9}},ExpressionUUID->"3caadde5-e91e-4781-aef8-\
df4ed6fd7047"],

Cell[BoxData[
 RowBox[{"{", 
  RowBox[{"20.708409`", ",", "Null"}], "}"}]], "Output",
 CellChangeTimes->{3.902996931397258*^9, 3.902997149544425*^9, 
  3.902997263547941*^9},
 CellLabel->
  "Out[172]=",ExpressionUUID->"7cd881ae-ccc8-438a-8e0d-238fc89f6cbb"]
}, Open  ]],

Cell[BoxData[
 RowBox[{
  RowBox[{"inputDataConsPop", "=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
     RowBox[{
     "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], ",", 
     RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
     RowBox[{"gNCutoffs", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"1775", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"1875", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"2000", ",", "1"}], "}"}]}], "}"}]}], ",", 
     RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
     RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
     RowBox[{"gDCutoffs", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"1775", ",", 
          RowBox[{"optimizedProductivities", "[", 
           RowBox[{"[", 
            RowBox[{"1", ",", "1"}], "]"}], "]"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"1875", ",", 
          RowBox[{"optimizedProductivities", "[", 
           RowBox[{"[", 
            RowBox[{"1", ",", "2"}], "]"}], "]"}]}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"2000", ",", 
          RowBox[{"optimizedProductivities", "[", 
           RowBox[{"[", 
            RowBox[{"1", ",", "3"}], "]"}], "]"}]}], "}"}]}], "}"}]}], ",", 
     RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
     RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
     RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
     RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
     RowBox[{"Pie", "\[Rule]", 
      RowBox[{"smoothedpie", "[", 
       RowBox[{"[", 
        RowBox[{"All", ",", "2"}], "]"}], "]"}]}], ",", 
     RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
     RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
     RowBox[{"precision", "\[Rule]", "precisionparm"}], ",", 
     RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
     RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
     RowBox[{"time", "\[Rule]", "timeparm"}], ",", 
     RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
     RowBox[{"Pie28", "\[Rule]", 
      RowBox[{"smoothedpie", "[", 
       RowBox[{"[", 
        RowBox[{"30", ",", "2"}], "]"}], "]"}]}], ",", 
     RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
     RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";"}]], "Input",
 CellChangeTimes->{3.9029972707145567`*^9},
 CellLabel->
  "In[175]:=",ExpressionUUID->"83fad209-0a00-49b9-92c5-a1119cf4fa74"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"{", 
    RowBox[{
    "initialDistributionConsPop", ",", "allParmsConsPop", ",", 
     "averageBeta2000ConsPop"}], "}"}], "=", 
   RowBox[{"findInitialDistributionHelper", "[", "inputDataConsPop", "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{
  3.898847884947712*^9, {3.899796553297093*^9, 3.899796574432724*^9}},
 CellLabel->
  "In[176]:=",ExpressionUUID->"6c4bf49f-67c3-422f-a2c4-bb1121b9ba5a"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ansConsPop", "=", 
   RowBox[{"solveModelHelper", "[", 
    RowBox[{
    "inputDataConsPop", ",", "initpointsx", ",", "initialDistributionConsPop",
      ",", "allParmsConsPop"}], "]"}]}], ";"}]], "Input",
 CellChangeTimes->{
  3.896953853944868*^9, {3.8969539432985764`*^9, 3.896953948255525*^9}, {
   3.898847648470461*^9, 3.898847653812191*^9}, {3.898847862980748*^9, 
   3.8988478756784563`*^9}, {3.899796761767501*^9, 3.899796766178438*^9}, 
   3.8997968750932007`*^9},
 CellLabel->
  "In[177]:=",ExpressionUUID->"a2800b94-5757-43a9-969f-7a8e5d6f4ebf"],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{"--", 
   RowBox[{"--", 
    RowBox[{"--", 
     RowBox[{"--", 
      RowBox[{"--", 
       RowBox[{"--", 
        RowBox[{"--", "-"}]}]}]}]}]}]}], "*)"}]], "Input",
 CellChangeTimes->{{3.896946629479751*^9, 3.896946631064043*^9}, {
  3.9027292111781187`*^9, 3.9027292125114193`*^9}},
 CellLabel->"In[54]:=",ExpressionUUID->"f97cc372-7fa0-4587-a302-f606b018f0ec"],

Cell[BoxData[
 RowBox[{"(*", 
  RowBox[{
   RowBox[{"Selection", " ", 
    RowBox[{"Only", "--"}]}], "-", " ", 
   RowBox[{"Full", " ", "Model"}]}], "*)"}]], "Input",
 CellChangeTimes->{{3.8969466275920467`*^9, 3.8969466348915462`*^9}, {
  3.902729214327286*^9, 3.902729218392568*^9}},
 CellLabel->"In[55]:=",ExpressionUUID->"a415602e-eed4-4002-981a-0a1dcc71ac6e"],

Cell[BoxData[
 RowBox[{
  RowBox[{"inputDataConsPopProb", "=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
     RowBox[{
     "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], ",", 
     RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
     RowBox[{"gNCutoffs", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"1775", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"1875", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"2000", ",", "1"}], "}"}]}], "}"}]}], ",", 
     RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
     RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
     RowBox[{"gDCutoffs", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"1775", ",", "0.9867869041583631`"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"1875", ",", "1.0868203664899094`"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"2000", ",", "1.327467228470097`"}], "}"}]}], "}"}]}], ",", 
     RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
     RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
     RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
     RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
     RowBox[{"Pie", "\[Rule]", 
      RowBox[{"Table", "[", 
       RowBox[{"Piessparm", ",", "30"}], "]"}]}], ",", 
     RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
     RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
     RowBox[{"precision", "\[Rule]", "precisionparm"}], ",", 
     RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
     RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
     RowBox[{"time", "\[Rule]", "timeparm"}], ",", 
     RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
     RowBox[{"Pie28", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
     RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";"}]], "Input",
 CellChangeTimes->{
  3.902997788422265*^9, {3.902997819075108*^9, 3.902997821324953*^9}, {
   3.903079232504603*^9, 3.9030792325789957`*^9}},
 CellLabel->"In[19]:=",ExpressionUUID->"18333b19-6b7e-44d1-9ac3-69c1d5f48db1"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"{", 
    RowBox[{
    "initialDistributionConsPopProb", ",", "allParmsConsPopProb", ",", 
     "averageBeta2000ConsPopProb"}], "}"}], "=", 
   RowBox[{
   "findInitialDistributionHelper", "[", "inputDataConsPopProb", "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.898849480770782*^9, 3.89884948358675*^9}, {
   3.899797005296921*^9, 3.899797016041513*^9}, 3.9029978263341007`*^9},
 CellLabel->"In[20]:=",ExpressionUUID->"7e5acee5-1452-4ef1-a453-6ef627e69d24"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ansConsPopProb", "=", 
   RowBox[{"solveModelHelper", "[", 
    RowBox[{"inputDataConsPopProb", ",", 
     RowBox[{"Join", "[", 
      RowBox[{
       RowBox[{"ansConsProb", "[", 
        RowBox[{"[", "2", "]"}], "]"}], ",", 
       RowBox[{"ansConsProb", "[", 
        RowBox[{"[", "4", "]"}], "]"}]}], "]"}], ",", 
     "initialDistributionConsPopProb", ",", "allParmsConsPopProb"}], "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{3.9029984087369747`*^9},
 CellLabel->"In[21]:=",ExpressionUUID->"de02e4e5-9a05-4f12-9677-a3352f6e4951"],

Cell[BoxData[
 RowBox[{
  RowBox[{"inputDataConsPopProbProd", "=", 
   RowBox[{"{", 
    RowBox[{
     RowBox[{"lrintr", "\[Rule]", "lrintrparm"}], ",", 
     RowBox[{
     "matchlrirBaselinyears", "\[Rule]", "matchlrirBaselinyearsparm"}], ",", 
     RowBox[{"stdevbeta", "\[Rule]", "stdevbetaparm"}], ",", 
     RowBox[{"gNCutoffs", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"1775", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"1875", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"2000", ",", "1"}], "}"}]}], "}"}]}], ",", 
     RowBox[{"gNyearsFuture", "\[Rule]", "gNyearsFutureparm"}], ",", 
     RowBox[{"gNss", "\[Rule]", "gNssparm"}], ",", 
     RowBox[{"gDCutoffs", "\[Rule]", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"{", 
         RowBox[{"1775", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"1875", ",", "1"}], "}"}], ",", 
        RowBox[{"{", 
         RowBox[{"2000", ",", "1"}], "}"}]}], "}"}]}], ",", 
     RowBox[{"gDyearsFuture", "\[Rule]", "gDyearsFutureparm"}], ",", 
     RowBox[{"gDss", "\[Rule]", "gDssparm"}], ",", 
     RowBox[{"\[Nu]", "\[Rule]", "\[Nu]parm"}], ",", 
     RowBox[{"\[Delta]", "\[Rule]", "\[Delta]parm"}], ",", 
     RowBox[{"Pie", "\[Rule]", 
      RowBox[{"Table", "[", 
       RowBox[{"Piessparm", ",", "30"}], "]"}]}], ",", 
     RowBox[{"Piess", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"lrconssh", "\[Rule]", "lrconsshparm"}], ",", 
     RowBox[{"nTypes", "\[Rule]", "nTypesParm"}], ",", 
     RowBox[{"precision", "\[Rule]", "precisionparm"}], ",", 
     RowBox[{"inityear", "\[Rule]", "inityearparm"}], ",", 
     RowBox[{"currentyear", "\[Rule]", "currentyearparm"}], ",", " ", 
     RowBox[{"time", "\[Rule]", "timeparm"}], ",", 
     RowBox[{"\[Omega]", "\[Rule]", "\[Omega]parm"}], ",", 
     RowBox[{"Pie28", "\[Rule]", "Piessparm"}], ",", 
     RowBox[{"percentiles", "->", "percentilesparm"}], ",", 
     RowBox[{"Nm1", "->", "Nm1parm"}]}], "}"}]}], ";"}]], "Input",
 CellChangeTimes->{{3.902998490947795*^9, 3.902998509309045*^9}, {
  3.9030792429280643`*^9, 3.9030792430700817`*^9}},
 CellLabel->"In[22]:=",ExpressionUUID->"73d48eda-c0a5-4483-9867-eb948c8bbc20"],

Cell[BoxData[
 RowBox[{
  RowBox[{
   RowBox[{"{", 
    RowBox[{
    "initialDistributionConsPopProbProd", ",", "allParmsConsPopProbProd", ",",
      "averageBeta2000ConsPopProbProd"}], "}"}], "=", 
   RowBox[{
   "findInitialDistributionHelper", "[", "inputDataConsPopProbProd", "]"}]}], 
  ";"}]], "Input",
 CellChangeTimes->{{3.898850049252967*^9, 3.898850051246564*^9}, {
  3.8997974161545486`*^9, 3.899797451674304*^9}},
 CellLabel->"In[23]:=",ExpressionUUID->"bd4551c2-87e6-4a6f-8a9b-2e119c35119f"],

Cell[BoxData[
 RowBox[{
  RowBox[{"ansConsPopProbProd", "=", 
   RowBox[{"solveModelHelper", "[", 
    RowBox[{"inputDataConsPopProbProd", ",", 
     RowBox[{"Join", "[", 
      RowBox[{
       RowBox[{"ansConsPopProb", "[", 
        RowBox[{"[", "2", "]"}], "]"}], ",", 
       RowBox[{"ansConsPopProb", "[", 
        RowBox[{"[", "4", "]"}], "]"}]}], "]"}], ",", 
     "initialDistributionConsPopProbProd", ",", "allParmsConsPopProbProd"}], 
    "]"}]}], ";"}]], "Input",
 CellChangeTimes->{
  3.898849985388302*^9, {3.8988500692070227`*^9, 3.898850074104698*^9}, {
   3.899797457375147*^9, 3.899797474263365*^9}, 3.899971280801504*^9},
 CellLabel->"In[24]:=",ExpressionUUID->"b63b9c4d-d393-4aa9-943c-cb4f997a060d"],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{
   "Define", " ", "a", " ", "list", " ", "of", " ", "names", " ", "for", " ", 
    "your", " ", "different", " ", "datasets"}], "*)"}], 
  "\[IndentingNewLine]", 
  RowBox[{
   RowBox[{
    RowBox[{"names", "=", 
     RowBox[{"{", 
      RowBox[{
      "\"\<Full\>\"", ",", "\"\<FullHomo\>\"", ",", "\"\<ConsProb\>\"", ",", 
       "\"\<ConsProd\>\"", ",", "\"\<ConsPop\>\"", ",", 
       "\"\<ConsPopProbProd\>\""}], "}"}]}], ";"}], "\n", 
   RowBox[{"(*", 
    RowBox[{
    "Initialize", " ", "an", " ", "empty", " ", "Association", " ", "to", " ",
      "store", " ", "the", " ", "resulting", " ", "tables"}], "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"ValuesToExport", "=", 
     RowBox[{"<|", "|>"}]}], ";"}], "\n", 
   RowBox[{"(*", 
    RowBox[{
    "Loop", " ", "over", " ", "each", " ", "name", " ", "in", " ", "your", 
     " ", "list"}], "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"For", "[", 
     RowBox[{
      RowBox[{"i", "=", "1"}], ",", 
      RowBox[{"i", "<=", 
       RowBox[{"Length", "[", "names", "]"}]}], ",", 
      RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", 
      RowBox[{"(*", 
       RowBox[{"Extract", " ", "the", " ", "current", " ", "name"}], "*)"}], 
      "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"name", "=", 
        RowBox[{"names", "[", 
         RowBox[{"[", "i", "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{
        "Compute", " ", "the", " ", "values", " ", "to", " ", "export", " ", 
         "for", " ", "the", " ", "current", " ", "name"}], "*)"}], 
       "\[IndentingNewLine]", 
       RowBox[{"temp", "=", 
        RowBox[{"computeValuesToExport", "[", 
         RowBox[{
          RowBox[{"Symbol", "[", 
           RowBox[{"\"\<ans\>\"", "<>", "name"}], "]"}], ",", 
          RowBox[{"Symbol", "[", 
           RowBox[{"\"\<allParms\>\"", "<>", "name"}], "]"}]}], "]"}]}], ";", 
       "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{
         RowBox[{
         "Add", " ", "the", " ", "current", " ", "name", " ", "as", " ", "a", 
          " ", "suffix", " ", "to", " ", "the", " ", "headers", " ", "in", 
          " ", "the", " ", "first", " ", "row"}], ",", 
         RowBox[{
         "unless", " ", "the", " ", "name", " ", "is", " ", 
          "\"\<Full\>\""}]}], "*)"}], 
       RowBox[{"If", "[", 
        RowBox[{
         RowBox[{"name", "!=", "\"\<Full\>\""}], ",", 
         RowBox[{
          RowBox[{"temp", "[", 
           RowBox[{"[", "1", "]"}], "]"}], "=", 
          RowBox[{"MapAt", "[", 
           RowBox[{
            RowBox[{
             RowBox[{"#", "<>", "name"}], "&"}], ",", 
            RowBox[{"temp", "[", 
             RowBox[{"[", "1", "]"}], "]"}], ",", 
            RowBox[{"List", "/@", 
             RowBox[{"Range", "[", 
              RowBox[{"2", ",", 
               RowBox[{"Length", "[", 
                RowBox[{"temp", "[", 
                 RowBox[{"[", "1", "]"}], "]"}], "]"}]}], "]"}]}]}], 
           "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", 
       RowBox[{"(*", 
        RowBox[{
        "Remove", " ", "the", " ", "first", " ", "column", " ", "and", " ", 
         "store", " ", "the", " ", "resulting", " ", "table", " ", "in", " ", 
         "the", " ", "Association"}], "*)"}], "\[IndentingNewLine]", 
       RowBox[{"If", "[", 
        RowBox[{
         RowBox[{"name", "!=", "\"\<Full\>\""}], ",", "\[IndentingNewLine]", 
         RowBox[{
          RowBox[{
           RowBox[{"ValuesToExport", "[", "name", "]"}], "=", 
           RowBox[{"Drop", "[", 
            RowBox[{"temp", ",", "None", ",", 
             RowBox[{"{", "1", "}"}]}], "]"}]}], ";"}], "\[IndentingNewLine]",
          ",", "\[IndentingNewLine]", 
         RowBox[{
          RowBox[{
           RowBox[{"ValuesToExport", "[", "name", "]"}], "=", "temp"}], 
          ";"}]}], "\[IndentingNewLine]", "]"}], ";"}]}], 
     "\[IndentingNewLine]", "]"}], ";"}], "\n", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
    "Join", " ", "the", " ", "computed", " ", "tables", " ", "horizontally", 
     " ", "to", " ", "produce", " ", "the", " ", "final", " ", "result"}], 
    "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"ValuesToExportFullDecomposition", "=", 
     RowBox[{"Join", "[", 
      RowBox[{
       RowBox[{"ValuesToExport", "[", "\"\<Full\>\"", "]"}], ",", 
       RowBox[{"ValuesToExport", "[", "\"\<FullHomo\>\"", "]"}], ",", 
       RowBox[{"ValuesToExport", "[", "\"\<ConsProb\>\"", "]"}], ",", 
       RowBox[{"ValuesToExport", "[", "\"\<ConsProd\>\"", "]"}], ",", 
       RowBox[{"ValuesToExport", "[", "\"\<ConsPop\>\"", "]"}], ",", 
       RowBox[{"ValuesToExport", "[", "\"\<ConsPopProbProd\>\"", "]"}], ",", 
       "2"}], "]"}]}], ";"}], "\n"}]}]], "Input",
 CellChangeTimes->{{3.899800481951412*^9, 3.899800493153013*^9}, {
  3.8998007194707336`*^9, 3.899800737886498*^9}, {3.900039435919449*^9, 
  3.9000394915573072`*^9}},
 CellLabel->"In[32]:=",ExpressionUUID->"26477c7a-37df-4c0c-b090-20d4a02508f0"],

Cell[BoxData[{
 RowBox[{
  RowBox[{"destination", "=", 
   RowBox[{
   "path", "<>", 
    "\"\</Outputs/Model/Full/modelOutputsDecomposition.csv\>\""}]}], 
  ";"}], "\[IndentingNewLine]", 
 RowBox[{
  RowBox[{"Export", "[", 
   RowBox[{
   "destination", ",", "ValuesToExportFullDecomposition", ",", 
    "\"\<Table\>\"", ",", 
    RowBox[{"\"\<FieldSeparators\>\"", "->", "\"\<,\>\""}]}], "]"}], 
  ";"}]}], "Input",
 CellChangeTimes->{{3.899800559617446*^9, 3.899800566391836*^9}, {
   3.9027292912652617`*^9, 3.902729300938456*^9}, 3.902824533930181*^9},
 CellLabel->"In[39]:=",ExpressionUUID->"d8564547-a25f-4ef4-803e-a1af51994866"],

Cell[BoxData[
 RowBox[{
  RowBox[{"(*", 
   RowBox[{
   "Generate", " ", "Table", " ", "2", " ", "from", " ", "model", " ", 
    "data"}], "*)"}], 
  RowBox[{
   RowBox[{
    RowBox[{"decomp", "=", 
     RowBox[{"Import", "[", 
      RowBox[{
       RowBox[{
       "path", "<>", 
        "\"\<Outputs/Model/Full/modelOutputsDecomposition.csv\>\""}], ",", 
       "\"\<CSV\>\""}], "]"}]}], ";"}], "\[IndentingNewLine]", "\n", 
   "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
    "Extract", " ", "header", " ", "and", " ", "data", " ", "separately"}], 
    "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"header", "=", 
     RowBox[{"First", "[", "decomp", "]"}]}], ";"}], "\n", 
   RowBox[{
    RowBox[{"data", "=", 
     RowBox[{"Rest", "[", "decomp", "]"}]}], ";"}], "\n", 
   "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
    "Convert", " ", "data", " ", "into", " ", "an", " ", "association", " ", 
     "for", " ", "easy", " ", "referencing"}], "*)"}], "\[IndentingNewLine]", 
   
   RowBox[{
    RowBox[{"assocData", "=", 
     RowBox[{
      RowBox[{
       RowBox[{"AssociationThread", "[", 
        RowBox[{"header", "->", "#"}], "]"}], "&"}], "/@", "data"}]}], ";"}], 
   "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"Define", " ", "the", " ", "models"}], "*)"}], "\n", 
   RowBox[{
    RowBox[{"models", "=", 
     RowBox[{"{", 
      RowBox[{
      "\"\<\>\"", ",", "\"\<FullHomo\>\"", ",", "\"\<ConsProb\>\"", ",", 
       "\"\<ConsProd\>\"", ",", "\"\<ConsPop\>\"", ",", 
       "\"\<ConsPopProbProd\>\""}], "}"}]}], ";"}], "\[IndentingNewLine]", 
   "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
    "Create", " ", "an", " ", "association", " ", "for", " ", "decompout"}], 
    "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"decompout", "=", 
     RowBox[{"<|", "|>"}]}], ";"}], "\[IndentingNewLine]", 
   "\[IndentingNewLine]", "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{
    "Loop", " ", "over", " ", "the", " ", "models", " ", "and", " ", 
     "calculate", " ", "the", " ", "desired", " ", "quantities"}], "*)"}], 
   RowBox[{"For", "[", 
    RowBox[{
     RowBox[{"j", "=", "1"}], ",", 
     RowBox[{"j", "<=", 
      RowBox[{"Length", "[", "models", "]"}]}], ",", 
     RowBox[{"j", "++"}], ",", 
     RowBox[{
      RowBox[{"mod", "=", 
       RowBox[{"models", "[", 
        RowBox[{"[", "j", "]"}], "]"}]}], ";", "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"decompout", "[", 
        RowBox[{"[", 
         RowBox[{"\"\<DeltaR\>\"", "<>", "mod"}], "]"}], "]"}], "=", 
       RowBox[{
        RowBox[{"assocData", "[", 
         RowBox[{"[", 
          RowBox[{"29", ",", 
           RowBox[{"\"\<r\>\"", "<>", "mod"}]}], "]"}], "]"}], "-", 
        RowBox[{"assocData", "[", 
         RowBox[{"[", 
          RowBox[{"2", ",", 
           RowBox[{"\"\<r\>\"", "<>", "mod"}]}], "]"}], "]"}]}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"decompout", "[", 
        RowBox[{"[", 
         RowBox[{"\"\<DeltaNc\>\"", "<>", "mod"}], "]"}], "]"}], "=", 
       RowBox[{
        RowBox[{"assocData", "[", 
         RowBox[{"[", 
          RowBox[{"29", ",", 
           RowBox[{"\"\<fert\>\"", "<>", "mod"}]}], "]"}], "]"}], "-", 
        RowBox[{"assocData", "[", 
         RowBox[{"[", 
          RowBox[{"1", ",", 
           RowBox[{"\"\<fert\>\"", "<>", "mod"}]}], "]"}], "]"}]}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"decompout", "[", 
        RowBox[{"[", 
         RowBox[{"\"\<DeltaNc23_0\>\"", "<>", "mod"}], "]"}], "]"}], "=", 
       RowBox[{
        RowBox[{"assocData", "[", 
         RowBox[{"[", 
          RowBox[{"24", ",", 
           RowBox[{"\"\<fert\>\"", "<>", "mod"}]}], "]"}], "]"}], "-", 
        RowBox[{"assocData", "[", 
         RowBox[{"[", 
          RowBox[{"1", ",", 
           RowBox[{"\"\<fert\>\"", "<>", "mod"}]}], "]"}], "]"}]}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"decompout", "[", 
        RowBox[{"[", 
         RowBox[{"\"\<DeltaNc28_23\>\"", "<>", "mod"}], "]"}], "]"}], "=", 
       RowBox[{
        RowBox[{"assocData", "[", 
         RowBox[{"[", 
          RowBox[{"29", ",", 
           RowBox[{"\"\<fert\>\"", "<>", "mod"}]}], "]"}], "]"}], "-", 
        RowBox[{"assocData", "[", 
         RowBox[{"[", 
          RowBox[{"24", ",", 
           RowBox[{"\"\<fert\>\"", "<>", "mod"}]}], "]"}], "]"}]}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"decompout", "[", 
        RowBox[{"[", 
         RowBox[{"\"\<Egy\>\"", "<>", "mod"}], "]"}], "]"}], "=", 
       RowBox[{"100", " ", 
        RowBox[{"(", 
         RowBox[{
          RowBox[{
           RowBox[{"Mean", "[", 
            RowBox[{"assocData", "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", 
               RowBox[{"\"\<gy\>\"", "<>", "mod"}]}], "]"}], "]"}], "]"}], 
           "^", 
           RowBox[{"(", 
            RowBox[{"1", "/", "25"}], ")"}]}], "-", "1"}], ")"}]}]}], ";", 
      "\[IndentingNewLine]", 
      RowBox[{
       RowBox[{"decompout", "[", 
        RowBox[{"[", 
         RowBox[{"\"\<Egn\>\"", "<>", "mod"}], "]"}], "]"}], "=", 
       RowBox[{"100", " ", 
        RowBox[{"(", 
         RowBox[{
          RowBox[{
           RowBox[{"Mean", "[", 
            RowBox[{"assocData", "[", 
             RowBox[{"[", 
              RowBox[{"All", ",", 
               RowBox[{"\"\<gn\>\"", "<>", "mod"}]}], "]"}], "]"}], "]"}], 
           "^", 
           RowBox[{"(", 
            RowBox[{"1", "/", "25"}], ")"}]}], "-", "1"}], ")"}]}]}], ";"}]}],
     "]"}], "\[IndentingNewLine]", "\n", 
   RowBox[{"(*", 
    RowBox[{"Round", " ", "the", " ", "results"}], "*)"}], 
   "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"decompout", "=", 
     RowBox[{
      RowBox[{
       RowBox[{"Round", "[", 
        RowBox[{"#", ",", "0.01"}], "]"}], "&"}], "/@", "decompout"}]}], 
    ";"}], "\n", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"Transpose", " ", "the", " ", "data", " ", "for", " ", "export"}],
     "*)"}], "\[IndentingNewLine]", 
   RowBox[{
    RowBox[{"exportData", "=", 
     RowBox[{"Transpose", "[", 
      RowBox[{"{", 
       RowBox[{
        RowBox[{"Keys", "[", "decompout", "]"}], ",", 
        RowBox[{"Values", "[", "decompout", "]"}]}], "}"}], "]"}]}], ";"}], 
   "\[IndentingNewLine]", "\[IndentingNewLine]", 
   RowBox[{"(*", 
    RowBox[{"Export", " ", "to", " ", "CSV"}], "*)"}], "\[IndentingNewLine]", 
   
   RowBox[{
    RowBox[{"Export", "[", 
     RowBox[{
      RowBox[{"path", "<>", "\"\<Outputs/Model/Full/decompout.csv\>\""}], ",", 
      RowBox[{"Prepend", "[", 
       RowBox[{"exportData", ",", 
        RowBox[{"{", 
         RowBox[{"\"\<parm\>\"", ",", "\"\<val\>\""}], "}"}]}], "]"}], ",", 
      "\"\<CSV\>\""}], "]"}], ";"}]}]}]], "Input",
 CellChangeTimes->{{3.903017749303253*^9, 3.903017750085926*^9}, {
   3.903017863544016*^9, 3.9030178900815477`*^9}, 3.903071620328843*^9, 
   3.903076639629365*^9},
 CellLabel->"In[41]:=",ExpressionUUID->"d3a3547a-25b5-45d1-8fb1-d8be5cad0aaa"]
},
WindowSize->{756, 916},
WindowMargins->{{51, Automatic}, {Automatic, 177}},
FrontEndVersion->"13.2 for Mac OS X ARM (64-bit) (January 30, 2023)",
StyleDefinitions->"Default.nb",
ExpressionUUID->"6f2118b7-8d89-4eef-a0fd-d0cfb5df0461"
]
(* End of Notebook Content *)

(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 559, 14, 52, "Input",ExpressionUUID->"72dbc847-9a88-4552-afb1-dde02e0e8916"],
Cell[1120, 36, 372, 9, 30, "Input",ExpressionUUID->"718de337-52d2-4236-91a8-b29b21012d14"],
Cell[1495, 47, 409, 10, 52, "Input",ExpressionUUID->"bb492a35-4d3f-41ac-9cef-2f281b17d81e"],
Cell[1907, 59, 1851, 37, 199, "Input",ExpressionUUID->"6c2681cd-2ec2-4472-8fcd-dfe31a54ff13"],
Cell[3761, 98, 423, 10, 52, "Input",ExpressionUUID->"78632e09-26a0-489a-8087-54a525f6305a"],
Cell[4187, 110, 594, 12, 52, "Input",ExpressionUUID->"43296670-d310-42a5-8ec5-563e504e15b2"],
Cell[4784, 124, 351, 9, 30, "Input",ExpressionUUID->"c1f3a51c-b7d6-4ac6-bb24-35f14cf3a0cf"],
Cell[5138, 135, 326, 8, 30, "Input",ExpressionUUID->"e39e5057-f3d6-42da-a5ce-5a1fba26e33e"],
Cell[5467, 145, 1165, 27, 136, "Input",ExpressionUUID->"0471509b-c23a-4774-b1f7-9d01592ab201"],
Cell[6635, 174, 8087, 163, 858, "Input",ExpressionUUID->"5c4ba096-8199-4b91-b92e-45c00fe62a84"],
Cell[14725, 339, 2010, 38, 220, "Input",ExpressionUUID->"6090a775-fc0d-4b12-a4ed-21df908219e5"],
Cell[16738, 379, 719, 15, 52, "Input",ExpressionUUID->"6d09ece2-981a-4c29-8f03-f34bf5f9ef60"],
Cell[17460, 396, 441, 11, 30, "Input",ExpressionUUID->"1d41a10a-8d52-4450-bee2-cf769fc0ee43"],
Cell[CellGroupData[{
Cell[17926, 411, 422, 9, 30, "Input",ExpressionUUID->"956b7155-555f-4347-9093-c4ce79e18db0",
 CellGroupingRules->{"GroupTogetherGrouping", 10001.}],
Cell[18351, 422, 23432, 482, 1658, "Input",ExpressionUUID->"74560a61-b829-4f5d-ae09-9fa335c4530e",
 CellGroupingRules->{"GroupTogetherGrouping", 10001.}]
}, Closed]],
Cell[41798, 907, 439, 9, 48, "Input",ExpressionUUID->"6ec84d96-93c2-4890-a0b3-de5ecd1c86bc"],
Cell[CellGroupData[{
Cell[42262, 920, 2462, 72, 262, "Input",ExpressionUUID->"da9a9949-171b-4467-8831-998576f31df8"],
Cell[44727, 994, 273, 5, 34, "Output",ExpressionUUID->"318d1276-c177-48bf-88df-b4cee19fdacb"]
}, Open  ]],
Cell[45015, 1002, 2344, 50, 241, "Input",ExpressionUUID->"2c013c77-694a-4045-9ae8-750b0072b7db"],
Cell[47362, 1054, 471, 11, 52, "Input",ExpressionUUID->"550baca7-3f9a-4dfb-bf30-bd8ce2e9d941"],
Cell[47836, 1067, 517, 12, 52, "Input",ExpressionUUID->"c8812f27-e91f-48e8-a1e1-cf223250f3cf"],
Cell[48356, 1081, 351, 9, 30, "Input",ExpressionUUID->"fe541328-63fd-4d33-9537-056bfbb689c1"],
Cell[48710, 1092, 328, 8, 32, "Input",ExpressionUUID->"1da176df-60e6-407a-9b1d-d34cae379d02"],
Cell[49041, 1102, 2063, 45, 199, "Input",ExpressionUUID->"8a6eff8e-573d-4cce-8335-727b41499ec4"],
Cell[51107, 1149, 499, 12, 52, "Input",ExpressionUUID->"680a5b4c-3e77-40d8-803b-627aec0e40b9"],
Cell[51609, 1163, 454, 12, 52, "Input",ExpressionUUID->"92d5da0e-8478-4cab-bb4c-3d91da0b34a7"],
Cell[52066, 1177, 488, 12, 30, "Input",ExpressionUUID->"da0625bc-83ca-464e-9529-af8b1726fdbe"],
Cell[CellGroupData[{
Cell[52579, 1193, 598, 12, 52, "Input",ExpressionUUID->"ceac3605-e385-4428-8eb0-cbb67318e8ad",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}],
Cell[53180, 1207, 21666, 451, 1654, "Input",ExpressionUUID->"086b1dec-63fc-468d-8daa-c72b2fdf8960",
 CellGroupingRules->{"GroupTogetherGrouping", 10000.}]
}, Closed]],
Cell[74861, 1661, 439, 9, 48, "Input",ExpressionUUID->"06f5af4f-370c-4081-9523-adac9a38e3a1"],
Cell[CellGroupData[{
Cell[75325, 1674, 2931, 78, 262, "Input",ExpressionUUID->"3caadde5-e91e-4781-aef8-df4ed6fd7047"],
Cell[78259, 1754, 257, 6, 34, "Output",ExpressionUUID->"7cd881ae-ccc8-438a-8e0d-238fc89f6cbb"]
}, Open  ]],
Cell[78531, 1763, 2649, 62, 241, "Input",ExpressionUUID->"83fad209-0a00-49b9-92c5-a1119cf4fa74"],
Cell[81183, 1827, 446, 12, 52, "Input",ExpressionUUID->"6c4bf49f-67c3-422f-a2c4-bb1121b9ba5a"],
Cell[81632, 1841, 592, 13, 52, "Input",ExpressionUUID->"a2800b94-5757-43a9-969f-7a8e5d6f4ebf"],
Cell[82227, 1856, 403, 11, 30, "Input",ExpressionUUID->"f97cc372-7fa0-4587-a302-f606b018f0ec"],
Cell[82633, 1869, 364, 8, 30, "Input",ExpressionUUID->"a415602e-eed4-4002-981a-0a1dcc71ac6e"],
Cell[83000, 1879, 2312, 50, 241, "Input",ExpressionUUID->"18333b19-6b7e-44d1-9ac3-69c1d5f48db1"],
Cell[85315, 1931, 510, 12, 52, "Input",ExpressionUUID->"7e5acee5-1452-4ef1-a453-6ef627e69d24"],
Cell[85828, 1945, 572, 14, 73, "Input",ExpressionUUID->"de02e4e5-9a05-4f12-9677-a3352f6e4951"],
Cell[86403, 1961, 2239, 49, 220, "Input",ExpressionUUID->"73d48eda-c0a5-4483-9867-eb948c8bbc20"],
Cell[88645, 2012, 504, 12, 73, "Input",ExpressionUUID->"bd4551c2-87e6-4a6f-8a9b-2e119c35119f"],
Cell[89152, 2026, 717, 16, 73, "Input",ExpressionUUID->"b63b9c4d-d393-4aa9-943c-cb4f997a060d"],
Cell[89872, 2044, 5088, 121, 598, "Input",ExpressionUUID->"26477c7a-37df-4c0c-b090-20d4a02508f0"],
Cell[94963, 2167, 636, 16, 73, "Input",ExpressionUUID->"d8564547-a25f-4ef4-803e-a1af51994866"],
Cell[95602, 2185, 7239, 197, 934, "Input",ExpressionUUID->"d3a3547a-25b5-45d1-8fb1-d8be5cad0aaa"]
}
]
*)

